Those laws were in large part the result of "Those who know best" do-gooders who used electroshock and concepts of eugenics and "Cuckoos Nest" treatments on the unwilling or gay or otherwise undesirables in the guise of psychology.  The courts finally acted and then the Legislatures.