Stock market prices depend on investors view on what the value of company is which in turn depends on what is its expected future profitability. For example, under a simple Gordon growth model the stocks would be valued using (See Miskin & Eakins Financial Markets and Instiutions pp 347):
$$ P_0 = \frac{D_1}{k-g}$$
where $D$ is the dividend, $k$ required rate of return and $g$ expected growth of dividend (and dividends directly depend on profitability). The model above is a simple model and there are more nuanced ones but the point from most models is that stock prices ultimately depend on firm's expected profitability.
Typically recession lower firm profitability but rarely shocks affect all firms the same way. For example, take Covid-19. Research shows that covid-19 primarily negatively affected industries like hospitality, transport, energy and so on (e.g. see Alonso et al (2020) or Shen (2020)). On the other hand many IT/technology firms benefited from the pandemic and lockdowns. More importantly, research shows that small and medium size businesses were affected mainly small and medium size businesses (e.g. see Dua et al (2020); Dua et al (2020); Alekseev et al (2020))*
The NASDAQ100 and S&P500 are tracking equities of 100 largest and 500 largest companies listed on the stock exchange. Consequently, shocks like covid-19 that hurt profitability of predominantly small and medium size companies that are often not even listed on stock exchanges (not even mentioning getting all the way to status 100 or 500 biggest firms respectively) will not affect stock prices as much as shocks that directly large companies, such as let's say .com bubble which mainly affected large technological businesses and correspondingly the S&P500 fell much more than during covid-19 crisis. This does not mean that covid-19 crisis was less worse for the economy than .com crisis since most firms in almost every country are small and medium size businesses. For example, according to the Eurostat in EU in 2015:
In 2015, enterprises employing fewer than 250 persons represented 99 % of all enterprises in the EU.
In the US according to SBE Council working with US 2016 census data showed that:
there were 5.6 million employer firms in the United States in 2016. ... Firms with fewer than 100 workers accounted for 98.2 percent. Firms with fewer than 20 workers made up 89.0 percent.
I think it goes without saying that typically (there might be exceptions) firms with less than 20 or even less than 100 workers simply wont make it to the S&P 500 or NASDAQ 100 or most of them might not even be listed. Consequently, stock market is not really 'the economy', it is just a part of it. Stock market is not a representative sample of firms, but sample of the large firms that decide to go public (e.g. small pop and mom shops would never get listed at stock exchanges because a) they do not need to raise that much capital; b) getting listed is expensive and publicly listed firms have higher regulatory burden so it does not make sense for most small firms financially). What even more, indexes such as S&P 500 and NASDAQ 100 look only at the largest firms from already sample of large firms (e.g. really the cream of the crop of the top crop). Hence these indexes are primarily affected by shocks to the profitability and expectations of the profitability of the listed large firms and there might be many macroeconomic shocks that can severely impact the economy as a whole but not as much largest firms or sometimes a macroeconomic shock that is negative for small and medium size business can be positive for large business (e.g. Covid-19 effect on restaurants vs technology giants).
Additionally, some economists as Paul Krugman** argued that stock market is getting more disconnected from the real economy because of savings glut and because wealthy individuals have not that many other good alternatives to invest in since bonds offer little return due to low interest rates.
Lastly, Fed's job is not to take care of the stock market prices. Fed pursues loose monetary policy (e.g. low interest rates, QE and so on) because that is the textbook 101 advice for central bank to purse in recessions (e.g. see Mankiw Macroeconomics). That this leads to asset price inflation is more of an side effect of the 'cure' for the real economy not the primary intent of Fed.
* Although an important caveat is that most of this research is preliminary as Covid-19 is recent event.
** However, this is opinion piece, consequently even if it is made by Nobel Prize winning economist please take it with extra grain of salt.