You're thinking too small, there: having some gay (and non-breeding, traditionally) family members has always been an asset to the health and survival of the family's genes. One of the reasons why gayness is so broadly represented across species is that it is a trait that helps a family's or a community's genes survive, especially in a species like ours where childrearing is a cooperative endeavor.
And, of course, there isn't a single gene that's responsible: life is complex. But here's an article about an Italian study that has some interesting points: https://www.newscientist.com/article/dn6519-survival-of-genetic-homosexual-traits-explained/