You are confusing "legal" with "right". "Right" refers to chosing the good between two alternatives in a matter of morals and conscience. "Legal" refers to what human acts the state has chosen to append penal sanctions to. Just because it is presently "legal" to kill unborn children does not make it "right", or confer a moral right on anyone to do so. Ditto for any state not outlawing sodomy.
In a good society, laws most closely conform to the right in order to encourage the populace to upright behavior. The more that they do not, the worse the society becomes and the more vicious the people become.