Who is trolling here ? Slavery was legal and immoral.
My question was about
things that were illegal.
The distinction is irrelevant, you can reverse it pretty easily: Since
slavery was legal, rescuing someone else's slave and freeing them (a
moral act) was illegal (it's theft, basically).
Of course, morality is an entirely subjective concept. At the time,
slavery was generally considered moral, since the people being
enslaved were considered lesser beings. It was when those morals
changed that people started to call for abolition. The law generally
follows morals, but lags behind a little. During the gap between
morals changing and the law catching up you can have immoral laws.