All of these tech companies (with perhaps the notable exception of Apple) massively overhired during the pandemic, and that overhiring was on top of a decade+ of the ZIRP era. So there are 2 main drivers of these layoffs:
1. Correcting pandemic overhiring
2. In the ~2010-2022 timeframe, tech companies poured all this money into speculative bets that never went anywhere, at least from a profit perspective (think Amazon's Alexa devices division, Google Stadia, and perhaps most famously the Metaverse itself). All those diversions are now toast, and they employed a ton of people. The only speculative bet that is now "allowed" is AI, which is one reason why I giggle whenever I hear people trying to defend their companies or projects by adding "AI" somewhere in the name.
So perhaps my second point is similar to your #2, but I think the important difference is that the end of the ZIRP era would have caused companies to kill these inherently unprofitable projects even if AI never came on the scene.