JOHANNESBURG—South Africa’s gold-mining companies are facing a question of life or death—and the answer is likely robots.

With more than half of the country’s gold mines currently unprofitable, companies are looking for ways to stay in business long enough to mine what is left of the world’s largest gold deposit. That means miners have to figure…