Restaurants are a businesses whose function is to supply food to people. So it would make sense to have them give water to people for free
Schools on the other hand are federal programs made for education. They probably aren't even obligated to have drinking fountains in the first place, why would they be obligated to let kids leave the classroom any time they want because they want some water?
You can get water before or after class. Teachers don't have to let you leave to get water, or even have water bottles. It's their room, so it's their rules.
Both of my parents have been teachers for years, so I can be certain in saying they are completely, legally allowed to disallow kids from having water bottles out.