People sometimes claim, usually in the context of things like gay marriage or abortion, that you shouldn't legislate morality. Usually, this is in response to the claim that gay marriage (or abortion, or prostitution, or whatever the topic at hand is) is immoral, and therefore should be illegal. But that's a bad response, because morality should be legislated.
Opponents of abortion are actually pretty good about pointing out the foolishness of this stance, by comparing abortion to murder. No one would say "If you don't approve of murder, then don't murder people." or "I don't like murder, but if my neighbor does, who am I to judge?" The response to that is usually that it's ok to have laws against murder because murder hurts people.
But so what? Why is ok to make a law banning something that hurts people? Because hurting people is immoral.
I think the main reason this argument is compelling is that it's usually used against people who are arguing against something that's not immoral. People say, "I think gay sex is gross, therefore it's immoral, therefore it should be illegal!". The argument is clearly flawed, but the flaw isn't with the second "therefore", it's with the first.
The problem is not with saying that something immoral should be made illegal. The problem is with misidentifying what is moral in the first place.
So, what is morality? How do you correctly tell if something is moral or not? That's a topic for another post, or perhaps a book.