Exactly.
Almost all laws are a legislation of morality, or at least a reflection of it. Morality is "what is right, what is wrong." Murder is illegal because we collectively believe it is wrong: this is a moral belief. Laws against having sex with a 13yo are laws because enough people believe it is wrong to do so... this is a societal expression of what we believe is immoral.
The only laws that are not an expression of morality in some sense, are those where Senator Bubbajay gets a special tax exemption for Developers Inc, in "thanks" for their campaign support... that's just plain old graft.
Adultery is widely considered immoral, but not as strongly as was the case 50 years ago. Then, many states had laws making adultery an actual crime. In the years since, society has become morally looser and collectively decided that that was too harsh... and most of those laws went away. You could call that a legalistic expression of our immorality, perhaps...
The point is, there's no point in arguing whether we should "legislate morality". We do. All the time. The only real question is "WHOSE morality do we legislate, yours or mine?"
In practice, it ends up being a little of both. What ends up being law, specifically what ends up being a crime, is often because a large majority of people find it morally reprehensible. Things that are considered morally reprehensible by a small minority are less likely to achieve legal standing.
That's just an overview of a much more complex subject, and skips over a lot of details, but you get the drift.