Of course it's a good rule. Offering healthy food alongside the junk food isn't necessarily going to encourage students to eat healthy food. I know this for a fact because, as a high school student, I would often spend my lunch money on soda and candy, instead of real food, if I wasn't that hungry. Granted, it didn't make me morbidly obese, but it wasn't a very smart move, either.
Yes, you could say that, idealistically, it should be up to the students to decide how they spend their money and how they eat. However, regardless of how the school system tries to set them up for adulthood by treating them like adults, teenagers are not adults and they don't act responsibly. In almost every other aspect of life, the law says that minors are not competent to decide what is best for them. Kids should be glad that the government leaves it up to irresponsible parents to decide how they eat.
There's honestly no reason to bitch about it, because if a kid wants soda and candy, and he can figure out how to get it elsewhere, and if he can't, then he's too stupid for soda and candy. There's no reason for schools to encourage bad eating habits.