So that every kid has a uniform and common base of knowledge that helps them understand the world around them, and enables them to go further by learning more or starting to work.
With no mandatory schooling, most kids would be illiterate and ignorant. A lot of countries, even developed ones, already struggle with the second (antivaxers, flat earthers, voting for dumb populists, etc.). Which indicates the need to improve, not remove.
If there was no schooling, how would kids becoming young adults even know what they're interested in to do? Would they know that e.g. chemistry or physics are things that exist if nobody explained the basics to them? Or would they just continue doing what their parents did, condemning them to a vicious cycle and almost zero social mobility? From history, the latter.