You answered your own question. For a lot of layoffs, cost reduction isn't the goal; it's disciplining the workforce who were increasingly assertive at work about direction and conditions.
It’s just the easiest way to make the stock price go up.
Layoffs caused twitter to bump in price. Same with Microsoft when they laid off all those game devs.
C-suite don’t care about profit or losses in tech, just the stock price.
In the 2010s, hiring devs increased stock prices. In the 2020s mass firings do.
It’s just money. Simple as.
For many companies the largest cost is labor. Also in many companies, managers amass power by the number of people they manage. If the C-suite doesn't explicitly push for layoffs they will likely not happen, causing them to not reduce costs as quickly as they wanted.
Regarding "managers try to amass staff," I've seen some of that for sure, but it's not universal and acting like it's some kind of iron rule of organizations is an op.
Most managers are evaluated based on the impact their organization is having, not the size of it, unless the firm is incredibly poorly run.
What does happen, and where these layoff edicts come from, is that the executives fear the management is more loyal to their directs than they are to leadership. They feel that if they want to inflict something on the workforce they have to "force" management's hand, because otherwise management will resist.