It's not so much of a habit as it is soothing to them somehow. My daughter started rubbing the back and side of her hair when she was nursing - probably around 6 months. She's 2 now and still, when she's tired, she will take her cup in one hand and rub the back of her head with the other. She has occasionally pulled it out, but does not currently.
Definitely speak to your pediatrician and ask for suggestions. In the meantime, try giving her a super-soft blanket (maybe fleece) to hold against her face or one of those tiny "blankies" with the animal attached. You might also try to get her to hold your finger or another soft toy or doll when she nurses to distract her.