For instance, there was nothing unconstitutional about Prohibition since it was in fact part of the Constitution. There was no doubt that this was a law based on morality. Ending slavery and preventing slavery from being legal in the US is based on morals that view slavery as wrong. Cruel and unusual punishment, morally wrong. Pretty much all of the rights that we have guaranteed to us are based on beliefs that something is either right or wrong, good or bad, and this belief is held by enough people that these protections have been enshrined within our Constitution, the main law of our land.
From there, laws are meant to uphold that base morality and maintain society. So, when we say that laws shouldn't be based on morals alone, it really is that those lesser tiered laws below the Constitution need to uphold the beliefs laid down by the Constitution, not a group of people's moral beliefs without any regard to the Constitution, or worse, in a way that violates some right/rights guaranteed by the Constitution.