However, I also think the government shouldn't step in and invalidate legal contracts that two parties entered in to. When you buy real estate, both sides have representation, and both are fully informed. There's a formal closing process and everyone has ample time to read everything. If someone is foolish enough to enter into a contract that isn't in their best interest, the Government shouldn't invalidate it.
I lived in Florida (outside of an HOA) when the State invalidated CC&Rs and HOA contracts to explicitly allow a person to fly an American Flag, and to permit solar panels. I happen to like both of these things, but I'd rather the market make these restricted properties worth less money because of these restrictions and let the market fix the problem.
I would have no problem if courts ruled or state government passed laws restricting what newly formed HOAs and CC&Rs could restrict. And I'd certainly love it if government mandates of HOAs for new construction was made illegal.