The grandmother is apparently the person providing the majority of her support, hence she gets to claim the little girl.

Hope that helps.