We don't have to go out of the school. Because if we go out of the school during breaks, accidents may occur like a student getting crashed by a car or people that can be wounded because of a busy street.
Also because a school canteen can be controlled by the school.
Example: If there is a policy that a canteen shouldn't have any softdrinks and junkfoods, it can be terminated by the school. Because the canteen is located inside the school premises and a canteen should obey the rules of the school.