You're right, at least in a way. At some point, other money has to enter in order for a valuation to make sense. In practice, this happens a few ways: a company starts paying out profits as dividends, it can use profits to buy back shares (which effectively works a lot like a dividend - a transfer of money from the company to its owners), or a company can stop being publicly traded (by being liquidated, sold, or re-privatized).
If a company doesn't do any of these, and never will, there'd be little reason to own their stock (not zero - there's still control and prestige and other marginal benefits - but nothing substantial). That said, it's perfectly reasonable to buy a company that's not currently doing any of these things - as long as there's an expectation that they'll do so later.
If a company is profitable, and they're plowing money back into effective growth (ie. making more money) that is often better for the investors than just paying the money out now. Apple would not be making billions now if it had not re-invested the millions it made in the past. (And now that it has billions of cash and can't effectively spend it all on growth, it's doing more dividends/buybacks).
Of course in reality, a company's valuation is not always terribly rational and things are often definitely overvalued. But in principle the market makes sense and is not a zero sum game. If nothing else, for those who don't trust "growth stock" valuation, there's certainly stocks that do still operate on a "pay out about 7% dividend, year after year, sort of basis".