The ruling was sparked by a case involving a Muslim girl who argued she should not have to take part in swimming classes because she would see bare-chested boys in their swimming trunks.
The 13-year-old from Frankfurt am Main took the case to Germany's top administrative court - The Federal Administrative Court in Leipzig - after losing the case at a court in Kassel, west Germany last year.
Judges in Leipzig said the girl could wear a full-body swimsuit known as a burkini to help maintain her religious beliefs.
It argued that in the summer, outside of school, men also went about bare-chested and school could not suppress the "social reality".
The girl claimed the right to skip the classes, with her lawyer arguing that according to the Koran, she was not only forbidden from showing herself to boys but also from seeing the topless boys.
The parents of the girl, whose family comes from Morocco, first complained two years ago that Muslim girls should not take part in co-educational swim lessons, but the school rejected the complaints prompting the court cases.