Mom used to say “You can’t legislate morality”. I agree.
Laws are about legislating morality, whether in the tax code, or murder, a society figures out what they consider moral, and then make it law.
And did Mom punish you if you lied, stole, or (God forbid), diddled your sister? If so, she was “legisltating morality”.
Sorry to be crude, but the mindless slogan “you can’t legislate morality” is meaningless Beavis and Butthead drivel. You can’t force bad men to be good via laws, but you can punish bad actions (aka “immoral actions”) and make such acts socially unacceptable and thereby curbed.
As a father of someone I knew said “locks keep honest men honest”.