In Japan school uniforms are distinct for each school, so it's easy to identify which school students belong to. Schools have reputation to maintain, especially in Japan where the lowering birthrate have forced many schools to close. Discipline is highly valued in Japanese society, so schools are expected to maintain high standards of it. Additionally, schools in Japan are expected to have a robust extracurricular program keeping students engaged and busy on school grounds as late as 6PM.
This means having students lounge around in public in their uniforms during hours when extracurricular activities are expected to happen, tarnishing the school's reputation for maintaining discipline and putting into question the robustness of their extracurricular program, can be a matter of life and death for the school itself. This is especially true of high schools because HS is optional in Japan and, unlike elementary and junior high where students are assigned by area of residence (school district fer Murricans), students and parents can freely choose which HS to go to. It's all about rep management.