This is exactly the strength of free market capitalism. It harness individual incentives (greed) to create socially beneficial outcomes. It doesn't rely on anyone to do anything outside of their own narrow self-interest, it just says to satisfy your own self interest you have to find a way to improve the lives of other people.
The richest people in capitalism aren't kings or popes or warlords. They're guys who invented cool things we all love.