They spent so long as king of the desktop that it went to their heads. They assumed they could just roll into the mobile market, say "Hey everyone, did you miss us?", and be greeted with cheers and enthusiasm. Meanwhile, the reality was that no one really liked Windows, they just sort of used it on the desktop because they had to.
Windows has been more than fine since Windows 7.
The problem with Mobile isn't that Windows Mobile or Windows Phone or whatever wasn't a good OS- because by all accounts it was- it was simply too late to the party, and most users were already locked into an ecosystem.
The Iphone and iOS was an 800 pound gorilla by the time Android launched- and the only reason Android was even competitive with it was that Apple locked itself into an insane exclusivity arrangement with AT&T for years, allowing Verizon (and to a lesser extent Sprint and Tmobile) to push their product FOR them.
By the time Windows Phone got off the ground both of those two had long been established and it takes either spectacular hardware or an amazing ad campaign to get people to drop an ecosystem they're already deeply invested in.
It was simply too late, no matter how good the product was.
edit: and yes I'm aware there was a windows mobile available prior to this (I have an HTC 6700 from like 10 years ago that runs it) but it wasn't marketed to or designed for the casual iphone crowd at ALL.