Yes, you can buy a bike in SA as a foreigner.
I don't think much has changed since these people did it:
http://www.horizonsunlimited.com/hub...le-south-80508
https://nonres-sa.com/motor-vehicle-...non-residents/
The traffic dept in SA is corrupt, inefficient and painfully stupid, but if you try hard enough it should be possible. Do some more research though.
I'm planning a similar trip to yours and also hoping I can sell the bike in Addis or somewhere in East Africa, and that's my stumbling block. Basically that seems to require importing the bike into whatever country to legally sell it, which means paying customs duties. I don't have any advice because I'm trying my best to find the same info as you about this, but some have told me it should be possible to sell the bike illegally- but not with a carnet.
My concern is I don't want to ride to Addis and turn around and go back to South Africa. I have read it should be possible to sell your bike if you meet a traveler who wants to buy your bike and ride it back to the country of origin.
A carnet shouldn't be essential for most of the countries on your route, but even here, the info I get depends on whom I ask.
Overlanding Association has a map of countries that require carnet, but most countries will (apparently) let you in with a TIP, or Temporary Import Permit. It's way cheaper than a Carnet and easier from what I understand.
Note the situation changes constantly, depending on bureaucracy, which border you go through, what the guards had for lunch, who you ask, etc etc.
Good luck!