Inflation and stock returns are completely different things
The CPI tracks the changes in the prices of a basket of goods a consumer might buy, the S&P 500 tracks the returns earned by investors in the equity of large companies. The two are very different things, and not closely linked.
Example: A world without inflation
Consider a world in which there was no inflation. Prices are fixed. Should stocks return zero? Certainly not. Companies take raw materials and produce goods and services that have value greater than that of the raw materials. They create new wealth. This wealth becomes profit for the company, which then is passed on to the owners of the company (equityholders) either in the form of dividends or, more commonly, price increases.
Example: A world with no inflation and no economic growth
Note that I have not implied above that companies have to grow in order for returns to outperform inflation. Total stock returns depend on the current and expected profit of the firm. Firms can remain the same size and continually kick out profits. Total returns will be positive in this environment even if there is no growth and no inflation. If the firms pay the money out as dividends, investors get a cash flow. If they retain these earnings, the value of the firm's equity increases. Total returns take both types of income into account. Technically the S&P 500 is not a total return index, but in our current legal and corporate culture environment, there is a preference for retaining profits rather than paying them out. This causes price increases.
Risk bearing
In principle, if profit was assured, then investors would bid up stock prices so high that profit would have to compete with the risk-free rate, which often is close to inflation (like, right now). However, profit is not assured. Firm profit swings around over time and constitutes a significant source of risk. We can think of the owners of the firm as being the bondholders and equityholders. These assets are structured such that almost all the profit risk is born by equityholders. We can therefore think of equityholders as being compensated for bearing the risk that would otherwise be born by bondholders. Because equityholders are bearing risk, stock prices must be low enough that stocks have a positive expected return (above the risk-free rate, which is presumably not significantly below inflation). This is true for the same reason that insurance premiums are positive--people have to be compensated for bearing risk.
See my answer to this question for a discussion of why risk means we should expect stock prices to increase indefinitely (even if inflation halts).
The S&P is not a measure of firm size or value
The S&P measures the return earned by investors, not the size of US companies. True, if constituent companies grow and nothing else changes, the index goes up, but if a company shrinks a lot, it gets dropped out, rather than dragging the index down.
By the way, please note that dollars "put into" equities are not stuck somewhere. They are passed on to the seller, who then uses it to buy something (even if this is a new equity issuance and the seller is the firm itself). The logic that growth of firms somehow sucks money out of usage is incorrect.