Microsoft were late to the smartphone OS market, but they
were making headway. In 2013 they were back into double digit market share in many countries, and the numbers were heading in the right direction. Then Ballmer left, Nadella took over, and they just... gave up.
OK, so they still had a long way to go before they displaced Android. But iOS only has ~30% of the market, and nobody is suggesting Apple give up on mobile because they're not the dominant player.
In the 90s, Microsoft were notorious for entering existing markets, usually with a substandard product, then grinding their way to a leading position. Even if it took years, even if they lost a lot of money at first, and even it took a few product cycles for them to become competitive, they stuck at it, and it eventually paid off.
This strategy worked for web browsers, office software, and console gaming. Would it have worked for smartphones? Maybe, maybe not. But I'd argue the signs were positive, and that they gave up before we really got a chance to see for sure. I mean, they've kept Bing alive for years, despite only having made minor headway against Google, and web search being a far less existentially vital market to them than operating systems.
Now, the problem with Microsoft's current strategy is that consumer IT is heading towards smartphones being the only device most people ever own or use. Desktops, laptops and tablets are becoming niche devices in comparison. It doesn't matter how great your UWP apps are if 90% the market doesn't own or use a device that can run them.