In a free society, one must recognize that legality ought loosely follow morality, with the ideal being that illegal actions are the strict subset of immoral actions which cause greater ill than the enforcement of their illegality. In the absence of an oracle into objective good and evil, a society must err on the side of not making things illegal which could potentially either be not worse than the ill of their enforcement, or not be immoral at all.
The all-to-common trap is to confuse the direction of influence: morality should influence legality, never the other way around. Allowing legality to influence one's perception of morality is simply surrendering your autonomy to those who greatest influence the law, and is a sure-fire path to authoritarianism.