The initial investment in chip fabs is so big it can't be justified when the established players already make enough to satisfy demand, but right now they don't so there's an opportunity.
It's still risky for sure but it makes some sense that it happens now. Hyperscalers spend 100s of billions yearly, at some point the amount given to TSMC gets larger than starting your own fab.
If success was guaranteed (it's not, as AMD and several others have learned) I think many more co's would start their own fabs in the current market.
As for why xAI, well why not - many of the others who can afford a fabbing attempt can't risk getting on TSMC's bad side even for a year or two.