Personally when I was in high school(And middle) I would do it all the time. Its part of my ADHD where I got to be moving at ALL times, even in the slightest of ways! So I would Lean back in my chair rocking it. The reason why teachers don't want you doing it is because of safety, there job, and the school could get fined. So the bored enforces it on the teachers, who in turn enforce it onto you. If you where to lean back in your chain and hurt yourself. The school could get fined or sued. But if you where warned and still do it, its your fault. And if teachers don't en fore it when they are told to, it can cost them pay or there job.
And at home, that's just because your parents love you and don't want you to get hurt.
What I did to fix my habit was get an Adirondack chair.(I made my own) Its basically a chair with legs that go back, insted of down and it is built to lounge in.