MS creating Xbox just to stop PlayStation involved a ton of sunk costs that can now be leveraged to stop Nintendo.
From MS' point of view Xbox succeeded just by taking money and would-be users away from PlayStation.
No PlayStation console has ever been as popular or as beloved as the PS2 and MS views that as success.
With the Switch approaching the PS2's level of popularity/love it's an obvious target with a weakness the PS2 never had - it's super easy to emulate.
From MS' point of view just disrupting the market with a handheld and causing Switch 2 to be less popular than Switch would be worth losing a massive amount of money.
Other factors to consider:
Revenge:
Nintendo laughed at MS' offer to buy the company.
Value: The idea of using the same stone (Xbox) to slow down two birds (PlayStation and Nintendo).
Facts: PC is the only platform that allows users to easily emulate Nintendo's entire game catalog from NES to Switch.