I don't get it either. It's not just religion, although religion can be used to justify it.
It's basically the ape mentality. Chimpanzees will fight with chimps whose territories border on their own, so they can get access to more fruit trees, which increases reproduction rates and infant survival.
Humans think they're somehow better than apes, but they still fight over who has access to more fruit trees, and they are threatened by anyone who is different.
Homophobia probably evolved because within a social structure (family group, clan, tribe, whatever) it's in everyone's best interest to have as many babies as possible to pass on their genes to the next generation. If the neighboring tribe is more interested in gay sex than straight, it's to your best interest because they won't have babies and will eat less fruit, but if members of your own tribe aren't making babies, it's a problem. So, that evolved into social taboos about gay sex, which in turn evolved into religious prohibitions.
It seems like too many people just don't think, so instead of thinking "It's perfectly fine that 2 people I don't even know are having non-reproductive sex, they don't share my genes and I really wouldn't gain anything if they made lots of babies. In fact, since overpopulation is a problem, I'm probably better off if they don't make babies." they just think "Gay sex bad! Sinful! Ugh! Need more fruit trees!"