Evolution does not explain homosexuality. Traits evolve as a result of greater reproductive success, and homosexuals are less likely to reproduce..
There are several possible explanations for this:
Although homosexuality probably has a genetic component, much of its cause, perhaps most of it, appears to be nongenetic (Haynes 1995; Kendler et al. 2000; Kirk et al. 2000). To the extent it is not genetic, selection would not affect it.
Homosexuals still have children. Sexual orientation is not an either-or trait but exists as a continuum (Haynes 1995). Those with some heterosexual orientation can still contribute homosexual genes (to the extent it is genetic; see above). And even the most extreme homosexuals sometimes have children.
The most manifest heterosexuals may have homosexual tendencies, too. Homophobic male heterosexuals showed more arousal to homosexual images than did nonhomophobic heterosexuals (Adams et al. 1996). Societal condemnation of homosexuality may contribute to its genes being propagated by causing latent homosexuals to behave heterosexually.
Genes for homosexuality could be beneficial on the whole. In bonobo chimpanzees, homosexual interactions are a form of social cement. It is possible that homosexuality evolved to serve social functions in humans, too (Kirkpatrick 2000). After all, social cohesion is still a main function of sex in humans.
The genetic etiology of homosexuality may come from a collection of traits that, when expressed strongly and in concert, result in homosexuality; expressed less strongly or without supporting traits, these traits contribute to the robust nature of our species. The genes for these traits persist because they usually combine to make us better at survival and reproduction.
Genetic factors linked to homosexuality in men apparently boost fertility in women. Female relatives of gay men, on their mother's side of the family, had more children than female relatives of heterosexual men. (Corna et al. 2004)
It should be noted that the question of explaining homosexuality is not limited to humans. Homosexuality exists in hundreds of animal species (Bagemihl 1998).
Adams, H. E., L. W. Wright Jr. and B. A. Lohr, 1996. Is homophobia associated with homosexual arousal? Journal of Abnormal Psychology 105(3): 440-445.
Bagemihl, Bruce, 1998. Biological Exuberance: Animal Homosexuality and Natural Diversity. New York: St. Martin Press.
Corna, F., A. Camperio-Ciani and C. Capiluppi, 2004. Evidence for maternally inherited factors favouring male homosexuality and promoting female fecundity. Proceedings: Biological Sciences 271: 2217-2221.
Haynes, J. D., 1995. A critique of the possibility of genetic inheritance of homosexual orientation. Journal of Homosexuality 28(1-2): 91-113.
Kendler, K. S., L. M. Thornton, S. E. Gilman and R. C. Kessler, 2000. Sexual orientation in a U.S. national sample of twin and nontwin sibling pairs. American Journal of Psychiatry 157(11): 1843-1846.