I wonder if it's one of those things that became religious because of early medical or pseudo medical procedures.
It's like, the "no pork" or "no shellfish" in the Bible probably had a real event of rotten meat or common seafood allergies in a population. But, evolved into people stoning someone for mixing cotton and wool fabrics together.
I'm just bull shitting. But I like to think silly religious things actually had some initial reason in a population before they were just silly beliefs.
The "no men sleeping with men" part was obviously patriarchal constructs. But it would be funny if it was just some jealous leader that realized he was gay after getting married "if I can't suck other guys dick no one can! Thus sayeth the Lord!"