an HOA is not a government so it is not the same thing, it might as well say the homebuyer must join the Boy Scouts
It is a legal contract and often it is on the deed, which is a legal document. So it’s an encumbrance like any other encumbrance on a deed. When you buy any property you have to look at the pre-existing encumbrances attached to its deed and decide if you want those or not.
Sometimes you can get encumbrances legally removed, say an easement for a gas line that is no longer in use. There is a process for that.