Capitalism rewarded the slave trade for generations.
The invisible hand is really human preferences. That's what will determine whether a company is punished for sexism or rewarded.
Humans stopped Apartheid. Not the abstract concept of capitalism.
Capitalism explains many things, certainly people stopped Apartheid, but it can very well be both, slavery and segregation are unproductive, and therefore anti-capitalistic.
Probably not to the slave owners, or anyone involved in the slave trade. They had little incentive to change.
Claiming that capitalism somehow spurs these things is the wrong way around. It can certainly benefit, but it's not the driver.
I think capitalism has a hand to play, to ignore it is naive. I think there was not one driver that ended slavery, but many things working together.
Note: I'm not saying there is no moral reason slavery is wrong, just that in addition it is contrary to the nature of capitalism.