When the Fed’s monetary inflation generates a credit expansion through the banking system as it does during a boom, entrepreneurs who borrowed the new money buy capital goods driving up their prices. As asset prices rise, claims to those assets also rise in value, i.e., stock prices rise.
Even when the Fed’s monetary inflation does not generate a significant credit expansion as is happening now (i.e., in a bust), investors who have liquidated their assets earlier in the bust and are holding cash begin to invest in assets and claims to assets in anticipation of their prices rising from the impending monetary inflation. Prices of commodities, land, houses, stock, etc. begin to increase even without improvement in the underlying economic conditions.
There are scenarios in which monetary inflation does not boost stock prices. For example, if price inflation is already raging, then more monetary inflation can collapse stock prices as in the 1970s.