When people attack the Catholic Church and her teaching on morality, they point to laws in past eras that were brutal by our standards. They argue that these past laws show that the teaching that “X is a sin” caused brutal punishments. That presumes law and morality are the same, which is false. Not all sins are against the law, and sometimes law interferes with moral behavior. St. Thomas Aquinas makes this distinction:
Now human law is framed for a number of human beings, the majority of whom are not perfect in virtue. Wherefore human laws do not forbid all vices, from which the virtuous abstain, but only the more grievous vices, from which it is possible for the majority to abstain; and chiefly those that are to the hurt of others, without the prohibition of which human society could not be maintained: thus human law prohibits murder, theft and suchlike.
Thomas Aquinas, Summa Theologica, STh., I-II q.96 a.2 resp. trans. Fathers of the English Dominican Province (London: Burns Oates & Washbourne,).
In other words, Not every sin was against the law in Christian societies. Morality distinguishes between right and wrong behavior. Morality tells what we must do or must not do regardless of what the law says. If theft is wrong, then we must not steal even if the law allows it. But while morality deals with what we must or must not do, law deals with what penalty we give when people violate morality in such a way that harms human society. Morality does not change over time, but laws can change over time.