There are different regulations in each state as to when compulsory school attendance ends or when a pupil can be released prematurely from compulsory education upon application by the school board. Some federal states (Bremen, Hamburg, Sachsen, Rheinland-Pfalz and Sachsen-Anhalt) have a uniform compulsory education with a duration of twelve years. It's eleven years in Hamburg. During this time, students must attend a full-time school. After nine years (ten years in Bremen) compulsory education can also be fulfilled by attending a part-time school (vocational school).
The obligation to attend a school in BW usually ends with passing a diploma at the end of the 10th grade or passing the “Abitur”.
For more information see https://www.service-bw.de/lebenslage/-/sbw/Schulpflicht+und+Schularten-5000836-lebenslage-0