system
Given the following post, respond as if you're commenting on Reddit:
human
Were there any reasons why homosexuality was so stigmatised in religious texts?

I know throughout history different cultures have had varying attitudes to homosexuality, but the attitudes mostly seem to be negative and often extreme, e.g. scriptures in many religions prescribe the death penalty for homosexuality. Even in societies where homosexuality was allowed, from my understanding they were still seen as less good than heterosexual relations, and often involved a master and slaves rather than consenting people. 

I am just wondering, were there any real social reasons why so many religions and societies became so anti-gay, to the point of prescribing the death penalty? For example we know many of the dietary restrictions in religions were originally made for safety or health reasons, to avoid eating foods that may kill you, etc. Was this sort of logic used when societies decided homosexuality was wrong? Did homosexuality bring about dangers to a society, that caused people to stigmatise it so much?
gpt
There is a lot of religious studies scholarship that brings together information from historical and linguistic sources to help understand why the holy texts of many ancient religions, especially the Abrahamic religions, condemned homosexuality. See, for example, Daniel A. Helminiak's What the Bible Really Says about Homosexuality.

One likely aspect is emphasis on procreation, since many non-procreative forms of sex are commonly condemned. Procreation might be particularly important for tribal societies vying for resources with other competing groups. Exclusive male homosexuality might be seen as particularly threatening in patrilineal societies.

Another element is the use of male-on-male rape as a form of asserting domination in some cultures. This could create an association of male homosexuality, at least, with humiliation and/or inhospitality.

As a final example, in some ancient contexts homosexuality was associated with temple prostitution. For cultures without those practices and particularly those in competition with groups with such practices, condemning same-sex sexuality could be an effort to reinforce cultural distinctiveness and ritual purity.