This paper contains interesting information and ideas on why as a whole humanity shifted its view of sex as a sacred and loving act of no shame and remorse to one of a sinful and condemned act unless needed for procreation. If you look at the period of time this paper covers you will see that the human population was exploding across the old world. Larger populations can make it hard for a social order to effectively pass on important views and practices. It can also make it harder to suppress people who would engage in destructive social practices. As such more and more inappropriate and destructive sexual practices may have become more and more prevalent making it an necessity for religious orders to try and push the populace back on track by becoming more and more restrictive on sex and making sex sinful in all but a few ways.
Larger and more mobile populations during this period may have also increased incidents of diseases including those that could be spread from sexual contact. Often these diseases were harmless or just a nuisance to the originating populace but once in an new group with no immunity they could wreak havoc. These diseases were sometimes construed by the people of the times as punishment for some sin against some god or another. People who engaged in allot of sex with many partners would have been more likely to get such diseases and therefore be sinful and punished by god. Religions of the time may have used free application of sex as a sin in attempts to constrain the spread of such diseases.
Also during this time many emerging religions such as Judaism and later Christianity used opposing ideas on sex from their “Pagan” counterparts in order to help make themselves stand apart. The older pagan religions were very free with how one could live their life while the later Zorastic religions sought to micromanage every aspect of a persons life. It is the polar opposite effect. Using this can garner followers to any idea that provides an alternative to one people may not be entirely happy with.