https://fortune.com/2022/03/31/us-companies-record-profits-2....
Everyone saw an opportunity to make MORE money during the pandemic, and instead of focusing on long term health, focused on quarterly profits. This lead to massive expansion.
The second answer is that these companies have mass layoffs every year. Are these really that abnormal, given the context of their mass hiring's the year before? Facebooks headcount went absolutely bonkers, they are still up over a two year period.
I think saying they were wrong is a mistake. It was more of a hedge on a bet, a bet they could afford to lose, but not afford to miss taking. It was akin to a game of chicken or mutually assured destruction, where if somebody else was expanding, you had to as well, defensively.