Legislatures and courts are ruling that gay is an identity category, like race or physical handicap, and not a behavior category, like being drunk-and-disorderly.
You've just put your finger on the distinction and the problem. Once people lose their moral compass, the law loses all rationality.