Sadly, this was the very point that many of us made to Microsoft at the time: even if Windows Phone is not making money today, keep it as a platform for the future. Once you shudder a project and give up those customers, getting any back is much more expensive. The internal skills and support infrastructure will also atrophy or disappear altogether. Further, the most loyal customers who stuck with Windows Phone, many of those were MS' core evangelists for anything new. MS alienated many of them. It would be like sponsoring an event for fans, then cancelling it at the last minute, after everyone booked their travel. It's just injecting poison into your core market: stupid.
I completely understand the financial analysis that led to closing down Windows Phone -- on any pure near-term profit modeling, that was clearly a rational decision. However, what they completely missed (and had no excuse to miss, because this is basic marketing strategy) is synergistic effect between those costs and other business lines and the long-term messaging to customers. Exactly as you have written here, Jez, Cortana, AI, Bing, future wearables, Xbox gaming, even full control over the mobile Office experience (one of MS' crown jewels) and mobile integration with Windows on PCs all benefited from the existence of Windows Phone. When MS dropped Windows Phone, that hit all of those in various ways.
Lastly, instead of teaching the market that MS sticks with its products, iterating on them until they are successful (a branding image they had from back in the Bill Gates days), which encourages users to try new things from MS, knowing MS will back them and any early problems will be solved. MS taught the market that it should never try anything new from MS. Always wait a year or two to see if it caught on, then you'd know if MS will back it. That's a self-destroying approach, because without initial users, there are never any users.