US taxes us on capital gains. OP is asking why the same money is taxed twice. You have simply restated the scenario what OP is asking about. The question is why are corporations taxed , not, what would happen if corporations are not taxed.
You seem to be talking past the parent comment. Their point is that a foreigner can make capital gains on an American company without America getting tax money. Double taxation patches that up.