There are numerous evolutionary mechanisms that might explain homosexual behaviour, which is common in many species of animals
"Simple reasoning shows that evolution cannot explain homosexuality - how would a homosexuality gene get selected for?" "Why have the genetic traits predisposing to homosexuality not been eliminated long ago?"
Such arguments are surprisingly common - and completely wrong.
Homosexual behaviour has been observed in hundreds of species, from bison to penguins. It is still not clear to what extent homosexuality in humans or other animals is genetic (rather than, say, due to hormonal extremes during embryonic development), but there are many mechanisms that could explain why gene variants linked to homosexuality are maintained in a population.
A common assumption is that homosexuality means not having children, but this is not necessarily true, especially in cultures other than our own. Until it became acceptable for same-sex couples to live together in western countries, many homosexual people had partners of the opposite sex. In some traditional societies, various forms of non-exclusive homosexuality were common.
Reasons why
Among animals, homosexual behaviour is usually non-exclusive. For instance, in some populations of Japanese macaques, females prefer female sexual partners to male ones but still mate with males - they are bisexual, in other words.
It has also been suggested that homosexuality boosts individuals' reproductive success, albeit indirectly. For instance, same-sex partners might have a better chance of rising to the top of social hierarchies and getting access to the opposite sex. In some gull species, homosexual partnerships might be a response to a shortage of males - rather than have no offspring at all, some female pairs raise offspring together after mating with a male from a normal male-female pair.
Another possibility is that homosexuality evolves and persists because it benefits groups or relatives, rather than individuals. In bonobos, homosexual behaviour might have benefits at a group level by promoting social cohesion. One study in Samoa found gay men devote more time to their nieces and nephews, suggesting it might be an example of kin selection (promoting your own genes in the bodies of others).
For your health
Or perhaps homosexuality is neutral, neither reducing nor boosting overall fitness. Attempts to find an adaptive explanation for homosexual behaviour in macaques have failed, leading to suggestions that they do it purely for pleasure.
Even if homosexuality does reduce reproductive success, as most people assume, there are plenty of possible reasons why it is so common. For instance, gene variants that cause homosexual behaviour might have other, beneficial effects such as boosting fertility in women, as one recent study suggests, just as the gene variant for sickle-cell anaemia is maintained because it reduces the severity of malaria. Homosexuality could also be a result of females preferring males with certain tendencies - sexual selection can favour traits that reduce overall fitness, such as the peacock's tail (see Evolution always increases fitness).
Given that, until recently, homosexual behaviour in animals was ignored or even denied, it's hardly surprising that we cannot yet say for sure which of these explanations is correct. It could well turn out that different explanations are true in different species.