If pedophiles don't breed, wouldn't their prevalence be significantly lower than it appears to be? Darwin 101, as you've mentioned before. And homosexuals, for that matter, shouldn't breed by definition. And yet up to 20% of respondents in modern anonymous polls report some level of homosexual tendencies these days.
Well the thing is, natural selection can
only work if total breeding success < 100%, therefore no species optimizes for 100% survival / procreation. There's also the fact that any number of developmental issues can make an organism turn out sub-optimal, even if there's one "perfect" way to turn out.
Wanting to have sex is the primary thing: without that you're not having many babies. Separately, the system needs to code in your primers for attraction. And concepts like "male" and "female" don't actually exist as objective binary categories. So evolution can only code for things like "attracted to faces", "attracted to a nice butt" etc etc. Because those categories aren't real things, evolution tries to
correlate your attraction to physical traits of the other gender, but it's only a correlation, not a binary thing.
Evolution doesn't deal in absolutes, only averages. Things aren't needed to be perfect, only to be good enough to replace the last generation. It requires two things: interest in sex, and who you're interested in. Those things are programmed in the womb by hormones, not directly by genes. That's the main thing to understand: genes do
very little directly, they do everything through intermediary chemicals, so they can only control things within a certain level of tolerance. The brains of everyone male and female start out neutral and they get imprinted by various chemicals. Genes can only loosely control that, and anything that perturbs the levels of those chemicals can make things turn out different.
So say the genome that turns out the horniest straight men and women 90% of the time also turns out 10% of people who are gay. Well, the birthrate just evolves to be 10% higher than it would otherwise. Humans have a lot more sex than most related primates, it might be that our much higher sex drive in general gives a survival advantage, but also causes higher rates of same-sex attraction and other sexual attractions.
It's a cost/benefit thing. Evolution
has a cost-effective strategy to deal with some organisms not maturing into active breeders: have more babies. That's a lot cheaper in evolutionary terms than "evolve to be 100% perfect and flawless".