The purpose of schools may seem obvious, but it is not, and it never really has been. Who teaches? Who is taught? For what purpose are they taught?
Schools require resources. We construct special buildings where teaching happens (unless the learners are apprentices who are learning in the workplace). We pay teachers, administrators, and other staff who provide instruction and manage and operate the school. We purchase instructional materials (unless we are using open educational resources). We maintain systems of governance and regulation. These resources come from public sources as well as tuition and other payments for the privilege of attending and for services provided at the school. The cost of attending school can be considerable. Attending a college or university to complete an undergraduate degree can cost tens of thousands of dollars per school year.
The obvious question is “why schools?” The question may be slightly different depending on the population one has in mind when answering, so maybe two questions should be posed, “why should governments provide public schools?” (where attendance in compulsory) and “why would one decide to enroll in school?” (where attendance is voluntary such as in higher education, job training, or massive open online courses).
My answer to the question “why school?” is increasingly centered around equity. There are skills and knowledge that is best learned when a learner has the guidance of a mentor. Teachers are those mentors, and governments (at least governments that claim any semblance of democracy) have an obligation to ensure all have access to those mentors.