You can find a thorough explanation at Scientific American, which can be summarized by one simple phrase: Natural selection isn’t all-powerful. There are other complicating factors that Jeremy Yoder mentions as well — I might summarize that as “evolution is more complicated than you think.”
He did leave out a few important factors, though. One is pleiotropy; same-sex preference could be genetically coupled to some other attribute that offsets the hypothetical cost in reproduction. Another is that, well, I haven’t seen any good data to show that homosexuals actually have a reduced reproductive success. Historically, gay men and women’s desires haven’t mattered much when social pressures push you into a heterosexual marriage with the goal of producing children, and also, just being heterosexual does not imply that you will have lots of children. What people want and what people do haven’t necessarily been tightly linked.
The biggest additional factor to my mind is that it may not be heritable at all (I’m not dazzled by the evidence for a heritable component). Yoder mentions that it could be polygenic, but not that it could be environmental. This is not to say that it is non-biological, or worse, a matter of choice: we know that hormones can affect the developing embryo in interesting ways, and we also know the mind can be shaped in significant and irreversible ways by early experience. He has some nice charts that show if homosexuality were transmitted as a single allele, the simplest possible case, it would still persist in our population despite selection, but it may be a completely irrelevant model.