At least 27 people have been killed in two separate mass shootings within hours of each other in South Africa.