Nokia had reached the end of the road on Symbian and needed a new direction.
This is a risky thing to do and going with Windows Phone gave Nokia the backing a very large and still influential company. Going with anything else would have meant going in alone. This includes Android which would be going alone into an already crowded market.
The current situation isn't great for Nokia, but they are in a deal that has the potential to help both companies, Nokia with short term financial help and Microsoft with a strong vendor to create showcase phones and the distribution network to get them into consumers hands.
Contrast this to RIM who tried to go in alone.
EDIT: fixed typo