First, “companies” don’t decide to layoff staff - people do (for now). So think about the people involved if you’re legitimately interested in how/why it happens.
Imagine for a moment you are the CEO and someone who may ultimately decide your pay or tenure asks “The future looks uncertain, what do you think?”. You’re very likely to think “I have no idea. I’ll ask the folks working for me.” and you do. You may get a mix of answers, a minority will be thoughtful but the majority will reflect the natural human tendency for self preservation, thinking along the lines of “Since the question was asked, it means I need to confirm the unstated assumption”, and be the one safe thing to say “We should cut spending”.
It’s just people being people.