The incident occurred on the eighth floor of the regional magistrate court building, where the divorce court was hearing the case between the couple, local media reported.
“At around 11 am… the suspect shot at the wife and her brother and both died at the scene,” police spokeswoman Colonel Thembeka Mbele, told AFP, noting that the hearing had been about to resume after a tea break.
The suspect turned the gun on himself but survived.
“He also tried to commit suicide and has been taken to hospital where he is in a critical condition,” she said.
A local reporter said that the two victims had been in the courtroom’s public gallery.
South Africa’s TimesLive online paper said visibly shaken court staff, including clerks and interpreters, were escorted from the building.
Security is usually tight at South African courts where visitors and workers pass through metal detectors and all bags are X-rayed upon entry.