I'm confident people understood the causality relations early on. But as time passes, the knowledge was progressively lost, and people were stuck with mis-understood habits: it's the "5 monkeys experiment"[0].
A Chinese friend once told me about the evolution of Confucius's interpretations: in the early days, a woman married to a poor excuse for a husband could be expected to leave him, for example so as to avoid her kids to imitate their father. Centuries later, breakups were strictly "haram".
The Muslims aversion for pork is another example.
The precise knowledge we have about poop's dirtiness is recent (e.g. first bacteria observed in 1676[1]; first virus in 1892[2]). Strictly speaking, we don't need divine books, but at some point, it probably was the only widespread, battle-tested option. Remember also that it was at a time with no Internet, and low literacy levels; people were different.
(I'm not intimate with the Bible's relationship with sodomy).
There's also the fact that the vast majority of people aren't receptive to rational arguments. Well-known, ubiquitous example: advertisement.
The fact that the Bible and others don't (always) give a why, do you think it's really a bad thing? There are valuable side-effects (let me leave this as an exercice).
[0]: https://intersol.ca/news/organizational-culture-and-the-5-mo...
[1]: https://en.wikipedia.org/wiki/Bacteria#History_of_bacteriolo...
[2]: https://en.wikipedia.org/wiki/History_of_virology