The attacks come as South Africa grapples with persistent gun violence often linked to gang rivalries.