Yasmin Omar, a lawyer who helped launch the court case, told state broadcaster SABC that the ruling was a temporary order “that will at least allow us to get emergency help to people (who) need it”.
She said a full hearing on the case would take place on Tuesday.
“These people underground are dying,” Ms. Omar said, adding that the ruling meant officials “must do everything they can to provide medical care to people underground.”
In a statement, the South African Police Service (SAPS) welcomed the court ruling, which it stressed did not prevent officers from making arrests.
It said: “Anyone who surfaces will continue to be assessed by emergency medical staff on site as before.
“Those who are healthy will be examined and detained, those who require additional medical assistance will be taken to the hospital under police protection.”
The SAPS added that as of 4:00 p.m. local time (2:00 p.m. GMT) on Saturday, three miners had surfaced.
More than 1,000 miners have already come out and been arrested.
South Africa is a country rich in minerals. According to official estimates, it contains almost 30% of the world’s gold deposits and 88% of all platinum deposits.
But many mines have closed in recent years and miners have been laid off, fueling a black market that costs the South African government hundreds of millions of dollars each year.