The fundamental reason is foundries work really hard to make sure they have zero idle time, by booking time months in advance, so there wasn't a lot of slack in the system to absorb the extra demand when it hit.
Add some confounding factors like, it takes a long time to build a foundry, in general the CAD is specific to a foundry, not every foundry can make every part, and even if they could, they're not licensed to then: You get a global chip shortage that takes many months to unravel.
As I understand it, there are lines with spare capacity, but the work to move manufactures takes time. Even for the same process/wafer size.
So it's not just a capacity shortage per se. Rather, a situation where real demand was wildly different (higher, and lower) than predicted demand, and re-spreading work is hard.
Add some confounding factors like, it takes a long time to build a foundry, in general the CAD is specific to a foundry, not every foundry can make every part, and even if they could, they're not licensed to then: You get a global chip shortage that takes many months to unravel.