Microsoft has gotten pretty good at software development. Satya Nadella has been doing a surprisingly good job reforming everything about the company.
That doesn't mean Windows wasn't absolute dogs--t for many years and isn't riddled with a pile of technical debt. Apple, in contrast, started with NeXTStep. I agree about the specifics you mention (built-in ads and spyware), but the core problems with Windows predate modern Microsoft, and can't really big fixed.
If, in 2024, Microsoft decided to invest in building a real mobile OS, I think they could do okay. The bigger problem would be lack of app ecosystem, and the chicken-and-egg problem with that and users. It's not clear even the best mobile OS could displace Android + iOS.
If I were Microsoft, and I wanted to get in, I'd probably fork Android, to maintain app compatibility. Doing that well would mean killing the goose which is currently laying the golden eggs, though, as it would require replacing Google apps with Microsoft ones. A lot of what makes Android work are free Google accounts, whereas Office 365 is $100 per year. I don't think a Microsoft phone would be competitive unless it had all the same stuff for free, and likely more.
I actually feel like Android is starting to be a little bit vulnerable; a privacy-preserving, non-user-hostile version could have pretty good uptake. Again, not the business Microsoft is in.