What was preventing them?
In short, they put their stockpiles of fissile material under IAEA monitoring and joined the Nuclear Non-Proliferation Treaty in 1991. This was still under the de Klerk government, while apartheid was still in the process of getting dismantled. (This is aside from its political unpopularity with the ANC — Mandela was himself a big supporter of the NPT and disarmament.) South Africa is also a signatory to (and major instigator of) the Treaty of Pelindaba, which bans nuclear weapons in Africa (1996).
If you would like extensive details, see David Albright and Andrea Stricker, Revisiting South Africa's Nuclear Weapons Program: Its History, Dismantlement, and Lessons for Today (Institute for Science and International Security, June 2016).