He took them from the employees of Microsoft who's work helped make those shares valuable.
Edit: Apparently this statement needs further clarification. What do those shares represent? A share of the profits. And what are the profits? Literally the difference between the company's revenues and expenses. It's literally the difference between the value created by workers and the salary the company paid them in return for that value.
So _of course_ Bill Gates took that wealth from the company's workers. That's what profit is!
----------
Now to expand on the broader idea, in a Democratic Socialist economy where the stock corporation is replaced by the worker cooperative, he would not have had the right to claim 500 million shares. Those shares would have been distributed to the employees of Microsoft based on some metric of contribution to the company. Or would never have existed in the first place, and each worker would have had a vote in how the company was run and the profits distributed.
In either method, Bill Gates would have gotten some still significant portion of the value the company created, but no where near the amount he walked away with in our current economy. The rest of that value would have been distributed to the company's workers in one way or another - profit distributions, shares, dividends, what have you.
In the minds of many - myself included - that is a much more equitable system. Bill Gates took the money from the people who helped create it in the first place. And he took a share that far out paced his contribution to the creation of that value.
He was able to do that because our economic system is set up around authoritarian companies, where the founders and CEOs have near dictatorial power (or oligarchical power with the board). And dictatorships are rarely equitable.