I don't believe it would be legal in Texas, but this is probably governed by state law. Here we have specific procedures for "Student Activity Funds". (I believe that's a common accounting term in the education arena. So it may help you in a search for your state.)
Here's a link to part of the accounting guidelines:
5.Site-based Decision Making
The Activity Fund is designed to account for funds held by a school in a trustee capacity or as an agent for students, club organizations of the campus, teachers and the general administration of the school. These funds are used to promote the general welfare of each school and the educational development and morale of all students. The accounting function for the Activity Fund is delegated to each campus and must comply with the guidelines and procedures required by this manual.
Each school has one "activity fund" bank account and all student organizations funds and class funds must be kept there and carefully accounted for as per state/district guidelines.
An independent organization such as a PTO or Band Boosters is - by law - outside this sphere and actually cannot have their funds held by the school. But school organizations/classes have no choice. The school would get killed in an audit if they allowed this.
What state are you in? I'm pretty sure that state law dictates this. Often times states follow pretty similar accounting procedures, but I haven't had experience with this specific topic.
You could also call your district and ask for a copy of the policy on how class/club funds are handled. But that might be opening a can of worms.