Maybe; or there could have been other reasons. For one, public companies have several audiences: shareholders and others with vested financial interests, certainly, but also the broader public, and (often forgotten by those commenting on company actions) employees. After a round of layoffs, there (at least) two groups of employees watching a company's actions: those forced to leave, and those who remain. Company leaders try to take actions that please the most and displease the least, and generally fail to varying extents due to misreading situations or to the scale of the actions as well as to the impossibility of delivering messaging that can speak to the issues important to such diverse audiences.
(Unsurprisingly, departed employees are pretty much always at the bottom of the priority totem pole in terms of trying to address issues. I was part of a layoff along with about half of my employer's total workforce. The messaging from my former employer was all about "everything is fine, we're in great financial position, we just wanted to better focus on growth opportunities", which to me as a newly unemployed jobseeker sounded a lot like "we didn't NEED to fire you at the height of the largest pandemic seen in a century, we just felt like it". Naturally, I didn't much appreciate that messaging, but I acknowledge that it was the right messaging for shareholders, and for the employees remaining who wouldn't want to feel like they were on a sinking ship.)
My specific point is that some things a company does that don't appear to make sense to an external observer, are at least sometimes done for internal reasons. One of the biggest risks a company takes in laying off people is the damage to morale of the remaining employees. A temporary hit to productivity is almost inevitable, and it can become a long-term, serious problem. One way that morale can be impacted is if part of the workforce sees another part as getting special treatment, i.e. I lost so many of my friends and other co-workers while X came out unscathed. Sometimes the damage of a layoff is spread around, at least a little bit, to address that; I've experienced it several times. Does it suck to get hit with layoffs when your particular department or organization has been kicking butt, even if it's to a lesser extent than other orgs? YES, IT DOES. But in terms of the emotional impact to other employees, at a company-wide level, the feeling of shared sacrifice can make sense to do that for long-term morale.
Please note: I am not defending the practice of layoffs in general, nor the inerrant wisdom of upper management, nor American/Western-style capitalism vs. any other economic systems. I'm just saying that given how things actually currently work, crappy situations arise, and people generall make the best imperfect decisions of which they're capable.