In South Africa, there are two options for foreigners who are in a relationship with a South African citizen or permanent resident:
If the couple is married, then a spousal visa would be required in order for the spouse to reside with the South African counterpart.
If a couple is not married, but has been in a long term permanent relationship (particularly, living together), a Life-partner visa will then be required in order for the partner to reside with the South African counterpart.
Therefore, it is not necessary to get married purely for the reason of entering South Africa and receiving a valid visa.