It seems to me much more likely that the answer will be more like “why do men have nipples?”
The structures in the human brain that cause sexual arousal are likely to be broadly similar in males and females. What causes an undifferentiated early embryo brain to develop into a male brain that is sexually attracted to females, or a female brain that is sexually attracted to males? It’s likely that a lot of these things are both present in the male brain and the female brain, it’s just that some are developed and expressed in the male brain and not developed in the female brain, and vice versa. Just like males have nipples, but never get the hormonal cues to develop swollen breasts or produce milk. But if you give a male synthetic female hormones, his breasts will start to swell, and he’ll start developing female secondary sexual characteristics. And vice versa.
Male rats given estrogen exhibit female mating behavior, female rats given testosterone exhibit male mating behavior. But that doesn’t happen with humans. If you give a gay man testosterone it doesn’t make him attracted to women, and if you give a straight woman testosterone it doesn’t make her attracted to women either, and vice versa for estrogen. A gay guy on testosterone is a butch gay guy, not a straight guy.
The point is, there are some mechanisms in the human brain that regulate sexual attraction, and we know these are shared up until adulthood in a rat brain and that rats can have their mating behavior changed simply by giving them sex hormones. Humans aren’t like that, but it seems pretty likely that somewhere during development these behaviors get built, although we don’t know when or how or what exactly, and at one point that embryonic or fetal brain isn’t gendered and at a later point it is. And if things develop one way that brain will end up attracted to males, and if it goes another way that brain will end up attracted to females, or maybe both or neither.
And that doesn’t mean it was advantageous for some people to end up gay, it just means that it happens, and perhaps that the extreme plasticity of the human brain is advantageous, and that sometimes things go wrong, but that’s a consequence of having a gigantic overdeveloped brain.
The other thing to consider is that while homosexuality probably isn’t some purposeful adaptation that benefits the extended kin group, or some such, it isn’t as deleterious to reproductive fitness as some people think. Gays and lesbians often have children, it’s not exactly unknown. A gay guy isn’t doomed to be the nurturing uncle that increases his inclusive fitness by caring for his straight sibling’s children, gay guys often have their own kids. I don’t know if anyone has done a study comparing the average number of children of gays vs straights, but that study wouldn’t show gays with no kids and straights with lots, there are plenty of straights with no kids too.
And we have to consider the effects of homosexuality on fitness, not in America today, but rather in the setting where human sexual behavior evolved…in small hunter-gatherer bands. It’s not obvious to me that a male hunter-gatherer who prefers to have sex with other males is doomed never to have offspring of his own.