South Africa remained a British colony until 1961, when it became a republic and left the British Commonwealth. The decision to leave the Commonwealth was made by the South African government, which was led by the National Party. The National Party had come to power in 1948 and implemented a policy of apartheid, which discriminated against black South Africans.
The decision to leave the Commonwealth was controversial, and many South Africans opposed it. However, the government argued that it was necessary for the country to be free from British influence and to be able to pursue its own policies without interference from the British government.
South Africa became a republic on 31 May 1961, and it was no longer a British colony.