If they build the new fabs and AI collapses then they still got all the AI companies' money because they prepaid. The current market price of chips is then going to crash, but that's what happens when AI collapses regardless. Might as well sell them five years worth of chips rather than two years worth of chips before the cash cow dries up.
Meanwhile, the fab companies want to think about what happens if AI collapses, but the AI companies don't. What do they care if they get screwed on a contract the day after they go bankrupt regardless? So offer them a contract where they get screwed if they go bankrupt, e.g. prohibit them from using any of the hardware for anything but AI for five years. Then the hardware is locked into AI stuff regardless of whether AI dries up and you can still go sell the rest of the chips that aren't to PC OEMs etc.