Index funds don't update their investment balance instantly, in part specifically to avoid this kind of problem. Most major indices require a stock to trade publicly for a minimum period (often 3 to 6 months) before they'll include them, and they rebalance on a fixed schedule - usually quarterly or semi-annually. A stock must wait for the next official rebalancing date to be added.
The things that might have been bit are Active Mutual Funds and Sector ETFs. These funds are focused much more tightly on specific sectors of the market and often buy "immediately" to ensure that they don't miss out on up-and-comers. FOMO can bite these more easily. But for that very reason they're not something that conservative investors like public pensions would invest heavily in, they're explicitly meant for the more gamble-oriented stuff. If you explicitly take a risk with your money then you should expect to lose it sometimes.
The S&P Dow Jones Index Committee explicitly rejected proposals to fast-track SpaceX.
The Russel 1000 and NASDAQ 100 did have "fast-track" rules for large IPOs like this. However, they have an additional guardrail that I think you overlooked here. When SpaceX went public only about 4% of the company's total shares were released to the public (the public "float"). The remaining 95%+ of the shares belonging to Elon Musk, early venture capitalists, and long-time employees are legally locked down and can't be sold for 90 to 180 days after the IPO. Index funds are weighted based on free float (only the shares actively trading), the amount of stock the fast-tracking index funds are actually forced to buy right now is very small, representing a fraction of 1% of most portfolios.
So no, this really didn't fleece 401ks and other conservative investment funds. They have rules in place specifically to prevent this sort of thing and outside forces can't "force" them to break those rules. Musk and other early shareholders were unable to dump their stocks during that initial IPO price spike and pension funds weren't buying the stocks up in significant quantities.