Have you ever been at a public school? Formal does not fit well in there... Where I'm from, teachers expect only a few things; that the students pay attention, do well in class, have as few days of absence as possible. Short of that, it almost doesn't matter.
Now, I understand what you're saying, and I get it. But does it really matter? If someone wears a hat inside, is it so fundamentally offensive and a grave violation? It's a piece of clothing, that shouldn't be of any concern either way. If your friend want to wear a hat inside, let him do it. He's not hurting anyone, and seeing as he is your friend, you already have some respect for him, and he for you. Are you going to burn a bridge because of a hat? Does this hat symbolize his depravity somehow? 'Cause I'm sure he probably just finds it comfortable or fashionable.
Yes I went to a public school, a religious one at that. It required you wear a white shirt and school tie with black shoes and trousers, as well as what you mentioned. Sure people work tracksuit tops and white shoes that were outwith the rules, they managed to police bright coloured jackets well enough but people still wear black denims and/or trainers.
I don't find it offensive or anything, and sometimes he has good reason to wear it; like forgetting to wash his haiir or something. But it's just manners, like taking your shoes off when entering someone elses house. It'd take more than a hat to burn that bridge, though at times I wish he wouldn't wear it because in certain ocassions it's not a respectable appearance, like when we're going out for drinks and trying to get into a club - The chances of getting in with a hat on and the casual clothes he wears is a nightmare. Is it that hard to take the hat off and put it away until you go outside again though?
Some places as well view hat wearers as a nuisance, because some tend to be neds and hooligans that wear them as a symbol of their degenerate life styles