Unruly means lacking in restraint or not submitting to authority. Spitballs, shouting kids, a shouting teacher — these are all signs of an unruly classroom. Often, one unruly student is all it takes.
It's easy to see how un- ("not") and ruly ("rule") create a word that is all about not following rules. When someone is unruly, they've thrown the rules out of the window. An unruly person refuses to obey authority, while an unruly piece of hair might refuse to stay inside a clip. And if a cat herder had trouble corralling kittens for a parade, there would be unruly kittens everywhere!