Ihm (personal pronoun, not possesive) means that it happened to the girl. Here's a similar example:
Das Blut sprang aus den Fingern. (Blood spilled from the fingers.)
Das Blut sprang ihr aus den Fingern. (To her it happened that blood spilled from the fingers.)
Not using the personal pronoun in the original sentence, leaves it technically undefined whos blood is spilling, although context strongly suggests that it's the girl's blood.
Comparable with the Latin Mihi nomen est (To me the name is) instead of
Meus nomen est (My name is).
Old answer (misread question, left for trivia):
Ihm refers to das Mädchen, which is grammatically neuter, while in fact a female. Likewise one would say:
Das Mädchen, welches... (neuter pronoun, correct)
Das Mädchen, welche... (feminine pronoun, wrong)
But in your sentence, I think it's possible to use ihr, too:
Das Mädchen musste sich täglich auf die grosse Strasse bei einem Brunnen setzen und musste so viel spinnen, dass ihr das Blut aus den Fingern sprang.
Mostly because Mädchen isn't perceived as a diminuitive* anymore, but rather as the standard term for "girl". Interestingly, the female version with welche sounds completely wrong.
*Magd (=maid, female) → Mägdchen (diminuitive, always neuter) → Mädchen