The stock market weirdly enough ruins the idea of capitalism. Catering to shareholders hurts the idea that competition would create better and cheaper products.
that's not the idea of capitalism; the idea of capitalism is that you should be able to make money by virtue of owning stuff. it's an inherently rich-get-richer scheme, competition has little to do with it.
Competition creating better products isn't an idea that defines capitalism though: the same would apply to cottage industry.
Capitalism is defined by having the capitalist, who provides capital, and without the ability to sell their share of stock it's difficult to see what the value would be. So you kind of require stock markets.
Edit: which is why it's odd to call China communist. They have 3 stock exchanges. They're really a capitalist single-party state.
Its not the stock market per se. The biggest problem is a lack of good regulation to ensure competition and the resulting drift of oligopolies.
The stockmarket enables that by making takeovers easier as you have a higher proportion of short termist shareholders who 1) fail to block value destroying acquisitions on one side and 2) jump at the chance to make a quick profit on the other.