If you’re in South Africa on a spousal visa (technically called a spouse/relative visa), it is linked to your relationship with your South African spouse or partner. Once that relationship ends (through separation or divorce), the basis for holding that visa falls away. This means that, legally, you may no longer qualify to remain in the country under the spousal visa.
However, if you are studying, you may be able to change your visa status from within South Africa or by applying from your home country.