"Learning" is the absolute main "function" of school, even though even most of the stuff you will forget it or you will never use it. I mostly learned from torturing myself, not from school. You can say it is for making friends but 1. I'm very lonely at school, i have almost no friends and all the time i am alone 2. Teachers quite literally do not like people having friend
I would say because the government and you parents say to.
Making friends might be a nice bonus if it happens but I would probably put it as more learning to deal with other people that don't care about you, which is pretty good training for life (possibly some of the best you will get in school).
Or if you prefer marketing figured out probably a century ago now (certainly at a point where anybody in school today would have had their grandparents learn it in school if they studied marketing) that age, sex and location is a fairly pathetic metric (which is all that binds people in school) and you instead want to go for interests, compatible mindsets and such like if you want the good stuff. Might have once meant something but as we are not in medieval villages any more where your village (and baseline survival) probably was your whole world.
More empirically then people that are friends with those from high school (proper friends, not just turn up to weddings and funerals) rates are rather low, and those that might be tend not to have the best life outcomes.
I don't have a particular easy solution to that one; if I did I would probably be very rich and suicide, depression and despair rates would drop notably on a country wide/first world country worldwide level. Online is demonstrably weak for that in the long run so real world clubs, classes for fun, learning enough psychology to vet people quickly, learning enough stats to figure out where to look and hardening yourself enough to pull it off is all I can offer. In my case I like building and fixing things so surround myself by people that do the same thing, have done things in their lives (usually at not inconsiderable costs on the pain and suffering front) and are the embodiment of will be generous up until the point at which you cross them. If your interests however are not that then no clue how to do that for you beyond the cursory stuff I mentioned already.
Teachers not liking people having friends... that is a new one. I could see it as a side effect of some of the warped views popular in the profession at present however.
I already said my bit on learning in a previous post. Can be a hard path to walk given the massive push for tests though. Learning how to learn, seeing if you can figure out adaptability (something schooling does not really touch on until the highest levels, despite it being 95% of life outside it) and if you are going to learn then fuck learning for the tests to forget it 5 minutes afterwards. Alas most examples people give of "I never used it again" I do actually use fairly regularly both generally and as a base to learn something more to do something more.