It's unlikely there's a gene that codes for being gay. Homosexuality instead is better thought of as more like why men have nipples. Obviously the nipples are not useful to the reproductive success of men, but genetics and natural selection are messy and there's likely no easy path to not having them in men while maintaining their function in women. For homosexuality, the systems of sexual attraction in the brain nee…
Umm... Men have nipples because they form before sexual differentiation occurs.
This is, or could be, just the how not the why.