Its my guess that the woodpecker was busily foraging for ants or grubs, one of their mainstay food diets, it is probably at its most vulnerable at this point.
The weasel always go's straight for the jugular, for a quick kill, so flying off was a life saving distraction.
A weasel can easily kill rats and rabbits, which are several times bigger than itself. Small but mighty!