Is this legal?

The HOA probably has broad governing power that they all have consented to. And if the HOA followed its own rules about the new garage issue (probably requires a vote by a majority of the board after a publicized meeting), then yes - it’s probably legal.

Seems like a dumb solution that might invite liability.

HOAs around here push the limit until someone busts them back into line. I would examine the covenants very closely before buying a home in a neighborhood with a HOA