Yasmin Omar, an attorney who helped bring the court case, told state broadcaster SABC that the ruling was a temporary order "that will at least allow us to get emergency relief to the people [who] need it".
She said a full hearing on the matter would take place on Tuesday.
"These people underground are dying," Ms Omar said, adding that the ruling means officials "must do all that is reasonable to give medical care to the people who are underground".
In a statement, the South African Police Service (SAPS) welcomed the court order, which it stressed did not prevent officers from making arrests.
It said: "All those who resurface will continue to be assessed by emergency medical personnel on site, as has been the case.
"Those that are in a good health will be processed and detained. Those that require further medical care will be taken to hospital under police guard."
The SAPS added that as of 16:00 local time (14:00 GMT) on Saturday, three of the miners had resurfaced.
More than 1,000 miners have already emerged and been arrested.
South Africa is a mineral-rich country. According to official estimates, it holds nearly 30% of the world's gold deposits and 88% of all platinum deposits.
But many mines have closed down in recent years and miners have been laid off, contributing to a black market that costs the South African government hundreds of millions of dollars each year.
In a bid to survive poverty, miners and undocumented migrants are increasingly entering closed mines to dig up their remaining deposits.
Some spend months underground, and illegal mining has spawned a small economy providing food and cigarettes to the miners.
However, the authorities are keen to end the practice. Illegal miners are sometimes recruited by criminal gangs and can be armed.