The thread below confused me, so I'll start another.
Britannica defines moral as: "of or relating to principles of right and wrong in behavior"
Murder is generally accepted as being wrong behavior (i.e., not moral). Therefore, it is legislated against.
Stealing is generally accepted as being wrong behavior (i.e., not moral). Therefore, it is legislated against.
Many other things are generally accepted as being wrong behavior (i.e., not moral) and are therefore legislated against.
To legislate against behavior generally accepted as wrong (i.e., not moral) is not "legislating morals." It is codifying what society has accepted as right and wrong behavior.
The problem comes when a society no longer is in agreement on some particular thing being wrong behavior. The component of society that feels a thing not to be wrong (e.g., murderers who feel they should be allowed to murder) complains about the other component "attempting to legislate morality." The component that wants a thing legislated against complains about deteriorating morals.
Our society in recent years has experienced a major upheaval of its standards of what is wrong behavior. Judeo/Christian teachings are no longer accepted as the source of morals by large segments of the population. Things that 100-years ago would have been viewed as immoral without question are now considered socially acceptable, even admirable.
It's simply silly to make a blanket condemnation of "legislating morals." It's also silly to attempt to legislate against those behaviors on which society at large do not agree.
Incidentally, just a fact I ran across, not to support prohibition, and not to create another thread, but it's not true that prohibition "didn't work." U.S. per-capita alcohol consumption was cut in half. However, prohibition created a new criminal class, just as current drug laws have, and ultimately was viewed by the populace as not being worth it.

