"Your diet is too spicy; try eating bland foods and maybe you'll masturbate less, SINNER!"
19th Century History
20th Century History
(media.piefed.social)
I think it originates from ancient social constructs. Because its very easy for men to knock up women and then abandon them and their child, it became necessary to have social rules to 'bind' couples through marriage. And strongly forbid sex outside marriage or adultery. In biblical times, adultery was such a severe crime it was often a death sentence.
These days contraceptives are so widely available it makes zero sense. But it made some sense in early civilizations thousands of years ago when infantcide was a very common practice.