Western Cape High Court judges Andre le Grange and Nape Dolamo ruled that the reasons given for the closures were brief and that the public consultation process that followed was inadequate.
They set aside Western Cape education minister Donald Grant's decision, made in October to go into effect from December 31.
Read more:
He and his department were ordered to pay the legal costs of the schools and their governing bodies.
The South African Democratic Teachers' Union (Sadtu), which was listed as an applicant, was ordered to pay its own costs.
Le Grange found that the reasons Grant presented for possible closures were largely inadequate and irrational.
"The applicants have demonstrated in the papers filed that the schools the provincial ministers decided to close have remarkable similarities to those he decided to keep open," he said in the judgment.
"The difference between the provincial minister's initial and final reasons for closure at certain schools … in my view gives further credence to the applicants' complaint of irrationality."
Argument dismissed
The court found the public consultation process an "artificial formality" that fell short of what was reasonably expected.
"The manner in which these proceedings were conducted further strengthened the applicants' case.
The officials simply allowed the affected parties to say what they wished to say rather than engage, raise, and discuss the reasons."
In a minority judgment, Judge Lee Bozalek said he would have set aside Grant's decision only for Beauvallon Senior Secondary School, and that the other schools had failed to make a case.
All three judges dismissed the applicants' argument that the section of the South African Schools Act dealing with school closures was unconstitutional.
Section 33 of the act empowers a provincial minister to close a public school by notice in the provincial gazette.
Grant announced last year that 27 schools faced possible closure for various reasons.
After representations were made at public hearings, he decided to close 18 schools and transfer pupils to "receiving schools".
'Sad day for education'
One of the schools, Tonko Bosman Primary in Somerset West, agreed to the closure. The schools' governing bodies and Sadtu approached the court for a review of Grant's decision on the closures.
The review application was heard last month and judgment was reserved. Grant said on Tuesday that the ruling marked "a sad day for education".
"The judgment has compromised the education opportunities for the learners at the 17 schools. The department will, however, continue to support these schools."
He said pupils at Tonko Bosman Primary, the school which agreed to the closure, had received better opportunities.
"The learners now attend Raithby Primary School, where they receive single-grade tuition and improved education facilities, such as a computer lab and sports and extra-curricular playing fields."
Grant believed the closure decisions were made in the children's best interests.
"We will study the judgment carefully and will take into consideration the recommendations made by the court in terms of procedures followed with respect to school closures."
Grant did not reveal whether he would appeal the court's ruling. – Sapa