The goal of an emergency fund is to be available for an eventual emergency. If you lose your job and need to live on saved up money for a few months, you might be forced to sell stock at the wrong time, losing capital. There is a middle ground where you invest that money in a low-risk investment product that will grow with time, without the volatility of the stock market.
To be fair, 6 month is a lot, and most likely not the first goal someone should have when it comes to personal finance starting from zero.
Shadow of Mordor in a nutshell.