The pandemic years saw companies accelerate their growth, even those who didn't have a clear 'pandemic angle' like Twilio. 2020 Q4 saw Twilio revenue growth 65% which encouraged them to hire more. Again, this is just the flip side of the current growth they are seeing (20-30%) which is causing them to re-balance their cost structure for lower growth.
There is risk in hiring during high growth periods - the risk being potentially these employees either won't deliver the value you expect, your strategy is wrong, or your growth rates won't continue. If these things happen, you might have to do a layoff. There is risk is NOT hiring during high growth periods too - if the company doesn't structure itself to capitalize on the current growth it is seeing, competitors could come in and sweep up market share.
At the end of the day, no one has a crystal ball for when high growth rates will stop, or when low(er) growth rates will pick back up again. In these cases, companies will hire during high growth periods and might have to lay off during low growth periods.
Many people seem to want to frame "layoffs" as a de facto failure, but it really isn't a failure as much as it is a company responding to dynamic market conditions (again, the flip side of hiring when growth is high). It's hard to say if the pandemic era hiring was really a bad idea - that hiring did fuel many of these companies to rapidly expand their revenue base and capitalize on many growth opportunities. Now that their future growth is expected lower, they are re-balancing their cost structure to respond.
Hindenburg made a music video compiling the references that is...uh...worth watching: https://www.youtube.com/watch?v=StjWk3Mj-M4