The City of Los Angeles passed an ordinance that requires all contractors to "disclose" all of their contacts and sponsorships (whatever that means) with the National Rifle Association. In Delaware, a man wants to apply to be a Judge on the State Bench. But, Delaware has a law that says that he is not qualified to be a Judge. Why not? Because he chooses to not associate with certain groups.
At the end of the day, the real question is why do governments continue to pass laws that they KNOW are not Constitutional. These Governments pay (with tax dollars) for legal advice, so it's not at all possible that they don't know this.
But even were we to be charitable and assume (yes, I know what it means) that they don't know, why do they keep proposing and passing laws that restrict liberty?