Failing to adhere to HOA rules (which may not be readily apparent) results in fines and conflict with a group that's empowered to make decisions about your property. When homeowners have these decisions taken away and are forced to shell out, it becomes a financial and psychological strain that prompts people who would otherwise be enjoying the property to leave (or to not purchase it in the first place).
My neighborhood has an HOA. I'm not allowed to use a grill on my deck. I can't just leave piles of trash in my yard. I can't install a garbage disposal unit in my sink. There are rules and the kind I would have really rolled my eyes at when I was younger.
But these rules, the HOA, they are required by state and federal law: https://www.hopb.co/new-hampshire
Condos are "common interest living spaces", if someone's house caught fire it can spread to the others. If the septic tank gets screwed up we all need to contribute to get that fixed. There are certain liabilities involved here that require some kind of legal entity to adjudicate, this is the role our HOA fills.
While I don't have the numbers, I speculate that the majority of HOAs in the United States were likely created for similar reasons. Fundamentally an HOA is kind of like the residential version of a workers cooperative, they enable high density housing where everyone gets to have equity. Living under an HOA will always be better than living under a landlord, yet I feel few make this connection, especially when considering who is more likely to discriminate.