I think this gambling argument goes both ways honestly. Investing in the stock market is inherently risky but traditional thought is that you invest where you expect a return that reflects this risk.
The are broadly two traditional investing styles. Value and Growth. Value investors look for stocks they believe are undervalued by the market (value stocks), while growth investors seek stocks that they think will deliver better-than-average returns (growth stocks). Value investors look for companies that have already earned their stripes and have a stock price that’s lower than it should be (and may rise again to reflect that). Growth investors look for companies with future potential and expect the stock price to increase (even if it’s already relatively high) as the companies reach or exceed that potential. Same desired destination, different ways of getting there. (
more here)
Both these styles rely a degree of due diligence being performed by the investor that gives them a basis from which to inform their investing decision. But they still could be wrong due to incorrect assumptions or unforeseen external events, and they could lose money. However, instruments exist to reduce their exposure to this risk (stop loss, stock options, futures etc.). I would argue this investment approach is not gambling, but still has a degree of risk. Other people will still see this as gambling however as different people have different risk tolerances.
Investing in a stock based purely on a gut feeling without any degree of due diligence on the underlying asset I would argue is gambling. In this situation, if the price goes up and you make money that was due to luck rather than any confirmation of an informed hypothesis.
But you can also take a completely different view. It could be argued investing, even on gut feeling, is not the same as gambling because investing increases the overall wealth of an economy, while gambling merely takes money from a loser and gives it to a winner. With gambling no value is ever created, whereas the overall wealth of an economy increases through investing. As companies compete, they increase productivity and develop products that improve lives.