This is a strange rule. I wonder if that sort of thing really is enforced in any Japanese schools.
Well, a lot of the manga schools are especially strict for the purposes of these sorts of stories, but bearing in mind that actual Japanese schools have done things such as telling people to dye their natural hair if it isn't black... I wouldn't put this past some of them either.
In this case, I suppose it's still fair enough. School is school, Valentines and White Day are completely irrelevant to what the school is for. So, if there's an existing rule against bringing stuff like sweets with you, it's not like they should be making an exception on one or two days for something that can be handled privately among people off school grounds anyway.