Money flows into the market when people earn it and use it to buy stocks. Every stock purchase is matched by a stock sale, but most stock sales turn around and become new stock purchases. That's a net long term inflow of money into the stock market, from people purchasing stocks with their earnings (often, via retirement funds).
Most of the actual trading is traders trading to each other, and that shouldn't raise the market cap long term (though it does create volatility). But there is also real inflow of money into the market.