First of all, it is not accurate to say that investing in the stock market is always a better financial decision. There are times where the stock market falls and you lose your investment. This does not happen with money in the bank. It is also true that the bank becomes a better option the closer you are to retiring and the more you need the money.
However, investing in the stock market is generally better than putting money in the bank because the long-term gains are likely to be (but not guaranteed to be) better. Bank deposits in the US today get very low interest rates. The interest rates tend to be lower than the rate of inflation. This means that you are actually losing a bit of value if you leave your money in the bank. By contrast, the stock market tends to bring good returns over the long term. Therefore, if you leave money in the stock market for a long period of time, you are likely to get better returns than if you leave it in the bank for the identical period of time.