Is this legal?

I don’t feel one ounce of sorrow. They choose to buy a house that allowed others to dictate what they can do with their home.
I understand the sentiment, but people don't always have a lot of options when it comes to home ownership. And homeowners should have some sort of expectation that HOAs will follow their own rules, and sometimes they change the rules after the fact. There are some well-run HOAs, and there are some terrible ones.

Do due diligence, and make sure an HOA is something you're willing to live with is about all people can do other than look for a property not part of an HOA.

Some areas, those properties are far and few between though.