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. An unruly person refuses to obey authority, while an unruly piece of hair might refuse to stay inside a clip.