Interesting question, that has not been completely answered. See, for some of the possibilities --
The evolutionary puzzle of homosexuality
http://www.bbc.com/news/magazine-26089486
And here is Prof Dawkins with his own take on the subject --
Darwin Day 2015 Questions: #4 How does evolution explain homosexuality?
https://richarddawkins.net/2015/03/d...homosexuality/