If a company decides to shutter a product or division, everyone might get laid off, from ground workers to middle management and even directors. If a company performs overall layoffs, it's going to lay off primarily from wherever they've overhired. One company might have overhired developers, another company might have overhired middle management, while a third company might have overhired sales.
Companies are generally trying to be pretty rational in only hiring positions that are required for the company to run/grow. Obviously they get this wrong all the time, but I'm not aware of any evidence they get this wrong more often about middle management.
I know there's a whole trope about middle management being useless, how you could cut it entirely and the company would still run just fine, but nothing could be further from the truth. A VP can't have 120 direct reports. There's no way for them to get the information they need to make good decisions, nor is there any way for their direct reports to get the information they need to make good decisions. It just doesn't scale.