How many times have you heard it? How many times have you agreed?
"You can't legislate morality" is a misunderstanding and myth which the majority of people in the U.S. seem to have bought into. It is a misunderstanding and miscalculation on the part of some, in that they propose that laws can't actually make or keep people moral (which is true). It is a myth and misrepresentation on the part of others in that they discourage and oppose laws they do not like, based on their so-called "universal truth" that "you can't legislate morality".
The fact is that laws by their very nature declare some behavior right and the opposite behavior wrong. Therefore, law in its nature and purpose correlates to the definition of morality. Morality is "a particular system of values and principles of conduct, the distinction between right and wrong." What happens in practice is not whether we legislate morality -- it is a question of whose morality we legislate! All laws are designed to encourage and discourage certain behaviour by citizens. They include penalties for citizens who do not accept/follow those behaviours. The government and law isn't neutral on issues like murder, theft, assault and rape -- they take a moral stand. Most everyone wants that kind of morality legislated! When law is enforced and crime is punished -- a manner of morality has been legislated.
"You can't legislate morality" has a modicum of truth with an elephantine edifice of error erected upon it. The shaky foundation cannot support the weight. Let it fall.