What would it take for something like the stock market to become illegitimate in the world's eyes? To the point of not investing, that is

Value and return destruction dissuading capital flows to the asset class.

end of fiat money or WW3.

Investors traded on stock markets even back when currency was backed by precious metals.

yes but nowhere near current % number of the popl. ? now a lot more people invest on it, big difference