Obvious religion was a primary reason, but where did the stigma in the religion come from? Why did the human authors of religious texts feel the need to condemn it? Basically I want to know why the opinions of populations shifted so drastically.
This is a great question u/cactus_licker3 because it's obvious something changed, but (as with all historical questions) when we pry into the details it becomes so so murky. So - was homosexuality commonplace and accepted in much of ancient history? Yes and no. There have likely always been people who felt this way, who we today would call gay; as there have likely always been people who felt outside their culture's gender binary, who we today would call non-binary. These feelings occur statistically and there's no reason to think they didn't appear historically as well. But, as you can tell, I'm side-stepping using these words outright because to say someone "was gay" in X ancient society when 1) we can't ask them, and 2) their society doesn't even use that word...Well this is quite difficult.
There are some societies where people are/were expected to participate in homosexual relationships, but they didn't call it "homosexuality." So we're in quite a bind, because we're basically saying to them: "I know more about your life than you did when you experienced it." The problem is that word and the identity it implies...prior to recent history there was no idea that individuals were 'a gay person.' Simply people existed and made choices, but this did not define their identity nor did it change their identity in relation to those other 'straight people.' Except sometimes, when there are individuals who appear to create an identity around their sexuality in opposition to their society's ambivalence. So are these people the actual gays while everyone else are simply straight people who bend the rules? It's often an impossible question to answer.
Basically all of history is comprised of us living in small practically egalitarian communities, and in these places it seems obvious that sexuality wasn't restricted by Christianity so then the answer to your question is a definite yes, it was accepted. But, when people talk about ancient history they often mean the last few thousand years which saw the rise of various "civilizations" etc (another contentious word), and sadly in these hierarchical and male-dominated societies we do see some version of a "homosexual identity" created and sidelined in opposition to heterosexual normalcy. But of course, this varies by time and place.
What contributed to it becoming so demonized, and did homophobia exist in Greco-Roman culture? These are related questions because Romans would've pointed out that homosexuality was unnatural and we today would call this homophobia. Of course, this did not stop people, but this general attitude was reinforced (and firmly encoded into law) when everyone converted to Christianity; a legal trend which would continue in Europe until the late 18th century.
This isn't my focus so I don't know the details, but there have been innumerable threads on this forum about homosexuality in history so there is much to read and delve into...
My Posts / Indigenous
If you're wondering about how Romans brought their biases into Christianity then I've talked about that in this post. If you're wondering about homosexuality in Africa (which maybe you haven't, but it's fascinating), I've talked about this in this post and a follow up in this post. There are some cultures who may not have any expressions of homosexuality (except as children!), which I've talked about in this post. Most of this info relating to Africa comes from the wonderful book Boy Wives and Female Husbands: Studies in African Homosexualities.
And aside from my writings, here's just a few from others on this wonderful sub...
Nahua/Aztec homosexuality by u/400-Rabbits
Third genders and homosexuality in the Americas, particularly the Nahua/Aztec and Inca by u/Kelpie-Cat
Indonesian third genders by u/KippyPowers
Greco-Roman
Ancient Greek homosexuality by u/cleopatra_philopater
Ancient Greek explanation for third genders by u/Ratyrel
Greco-Roman homosexuality by u/semajijohn
Greco-Roman homosexuality by u/boo_cait
Roman homosexuality by u/Steelcan909 and u/sunagainstgold
Roman homosexuality by u/i8i0
Roman homosexuality by u/WelfOnTheShelf
And there are two papers which come to mind... The influence of Roman laws regarding same-sex acts on homophobia in Africa, by Susan Haskins http://www.saflii.org/za/journals/AHRLJ/2014/21.html and Roman Sex, Sexuality, Slaves, and Lex Scantinia, by Markus Milligan www.heritagedaily.com/2013/08/roman-sex-sexuality-slaves-and-lex-scantinia/97996
Medieval
Islamic Golden Age homosexuality by u/Kelpie-Cat
Islamic Andalusian homosexuality by u/Kelpie-Cat
Medieval homosexuality by u/GlampingNotCamping
Medieval homosexuality 1 and 2 by u/sunagainstgold
Medieval homosexuality by u/concinnityb
Medieval homosexuality by u/BRIStoneman
Medieval homosexuality by u/CrankyFederalist
And some papers... The Experience of Homosexuality in the Middle Ages, by Paul Halsall, and Take up Riper Practices: The Gay Love Letters of Some Medieval Clerics, by Rictor Norton http://rictornorton.co.uk/medieval.htm
Early Modern and Recent
English Early Modern period homosexuality and Roman galli priests by u/concinnityb
Ottoman homosexuality with answers by u/paxottomanica, u/Chamboz, and u/gamegyro56
And this article...What Ottoman erotica teaches us about sexual pluralism, by Irvin Cemil Schick
Whew, have fun reading!