I didn't read all the other responses, but did see someone mention trichtotillimania. My daughter has it and she is 4. She would only do it at night time. It originally started out as twirling, then the twirling turned into knots, turned into pulling it out. I didn't realize she was doing it one day until I moved her night stand and found her "stash" of hair. My heart just broke into a million pieces. My oldest daughter sees a therapist due to her ADHD, so we asked her about it. We are now re-training her to soothe herself. We got her a "bedtime" baby to only use at bedtime and she can stroke and pet the dolls hair, but not her own. I now also lay with her at night time to re-train her. Now I am only laying with her for 3-5 minutes....where I was originally laying with her until she fell asleep so I could guarantee she wouldn't pull her hair out.
It is a phase and will pass, but we don't want our daughter's to lose their hair in the mean time. (My daughter's hair is growing back in, but it's been a long process). I don't know that I have any suggestions for a child that young. Other suggestions the therapist mentioned was wearing a hat (yet they can just take it off), finding a new lovey that they can take to bed that they can stroke, feel, pet, etc. My heart goes out to you. We are still working through this ourselves. Message me if you ever need to talk.
~K.