This is similar to the fact that there is nothing wrong with prostitution in the Bible as long as not in the Temple worshipping the fertility gods which was the "sin" - idolatry, not sex was the issue.
Lots of references to non-goddess prostitutes with no negative inference.
Adultery, of course, was a property crime since the husband owned all his women, concubines etc. The man could have as many sex partners that he could afford or want as long as the women were single - not owned by a husband.
Likewise, premarital sex totally accepted once the bride price was paid to the father but had to wait until age 11/12 marry. But once betrothed and when the deal was done, no problem having sex.
The idea of Priests being celibate was because all the children were costing the Church too much money so it had to be stopped. Thus celibacy and of course the attraction of gay priests since being celibate is against nature and not natural.