Well yea... You're right. you shouldn't. Masturbation is a private activity meant to be done in a private place by yourself. Not in a public bathroom at school. Although, I understand what happened. It's a cheap thrill and sexually excites some people at the risk of getting caught. It's not worth it.
Wow. Masturbation is meant to be done in private. 1. You'd most likely be sent to the office 2. Your parents would know 3. Everyone at your school would know. Trust me stuff like that spreads like I can't beleive it's not butter.
I'm pretty sure that's not allowed. It most likely isnt going to be listed as an offense in your student handbook but any type of sexual act is not permitted in school. (Or school bathrooms for that matter)
For this reason alone I say you probably should not be doing it.