They are absolutely against the law. The problem is that none of it is enforced in any manor. Try calling the police in most places for something that isn't an emergency. They'll tell you to file a report, and they'll look into it at some point(hint: they won't).
At least with HOAs, they will fine you and possibly take your house. For these extreme cases it's a great way to keep people in shape. I guess the problem is when they get abusive and try to do the above for yard weed, paint, or other benign violations.