As it is with many things, the answer depends on where in the world we're talking about. In addition, there are a couple of different ways of thinking about the notion of mandatory school attendance. First, there's the legal and bureaucratic framework associated with what's described as "compulsory" and universal education. Most American states, Canadian provinces, and European countries had such structures in place by the early 1900s. The 1924 adoption of the Declaration of the Rights of the Child by the League of Nations implied a child's right to an education and the right was stated explicitly in the United Nation's 1959 update.
- The right to equality, without distinction on account of race, religion or national origin.
- The right to special protection for the child’s physical, mental and social development.
- The right to a name and a nationality.
- The right to adequate nutrition, housing and medical services.
- The right to special education and treatment when a child is physically or mentally handicapped.
- The right to understanding and love by parents and society.
- The right to recreational activities and free education.
- The right to be among the first to receive relief in all circumstances.
- The right to protection against all forms of neglect, cruelty and exploitation.
- The right to be brought up in a spirit of understanding, tolerance, friendship among peoples, and universal brotherhood.
That said, the look and structure of formal education in various countries was shaped by colonialism, which groups had access to power, and which families experienced scrutiny or charity when their children didn't attend school.
Second, there are the social and cultural norms around which kids are allowed to go to school. Most American states had compulsory education laws on the books by the late 1800s but Black, Indigenous, Asian, and Mexican children were often explicitly barred from attending classes or required to attend schools with fewer resources. We see this pattern in different ways in different countries - adults would deliberately exclude children from school, based solely on their race and/or gender and/or social and/or economic status. Meanwhile, it wasn't until the modern era - 1975 in the United States - that schools were required to educate children with disabilities. It was the norm until well into the 1900s around the world that children with physical, cognitive, or emotional disabilities were excluded from mandatory school attendance or worse, steered into separate schools, regardless of their abilities. But, to be sure, this wasn't a universal truth. There are lots of examples of people with disabilities participating fully in their community, including during their childhood and adolescence.)
Finally, there's the enforcement structure around the laws and social norms. That is, in the early 1900s, many large American city school systems created the role of the truancy officer and the structure around the person to enable them to track down children who failed to attend school. In many cases, this was tied to the shift to a per pupil funding structure. If seats were empty, the school wouldn't receive the funding for that child so it benefited the school to ensure the seats were full. (But again, children with disabilities were often excluded from school, as were Black children from schools built for White children.)
From about the 1910s to the 1940s, public school attendance in the United States was mandatory, with no carve outs for homeschooling and limited exceptions for private school. (Which doesn't necessarily mean every child attended and it was fairly common for children to leave school after 8 or 9 years, not the 12 or 13 we see today.) A series of court cases change the norm which means, without getting too much into the modern era in the United States, going "to" school isn't mandatory. A 1972 Supreme Court case, Wisconsin v. Jonas Yoder, made it official that parents had no obligation to send their child to school. Because of the 10th Amendment, it's been up to each state to set up their own education system, as well as homeschooling oversight, which means there is a high degree of variability between states.
So, in effect, it's still not technically mandatory for all children to go to school but as laid out in the UN's Declaration of the Rights of the Child, adults are required to ensure every child gets an education and that looks very different in different countries, states, and provinces. (In 20 years, we can talk about the recent court ruling that found literacy is a basic right owed to American children.)