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.