‘You cannot legislate morality.’ is an idiotic statement.
Of course we can legislate morality — that’s explicitly what most legislation (historically) has been, and what most legislation should be.
You cannot impose effective ‘prior restraints’ upon immoral behavior, sure, but that is not an argument against the legislation of morality.