That is an actual law of the land in a democratic society that could change it if we all wanted. Everyone plays by the same rules there.
Meanwhile an HOA deed restriction is you giving a private non government organization the permanent and irrevocable right to remove you from your home and sell it if you do not comply with whatever extra-legal discrimination they make up to impose on you.
Plain and simple, HOAs are not a country or a government. They are a scam.