Someone posted the same question regarding her 6 yr old and this is part of my response to her:
Don't freak out - it is not totally uncommon. Explain about privacy and that she can only do this in privacy and that those are HER private parts and NO ONE else is allowed to touch them. I would probably say "Do you need some alone time in your room?" when she does it.
This is called "self-stimulation" and kids who self-stim often masturbate, or rock back and forth, often before sleep, etc. It is similar to thumb sucking and they get comfort and calming from that, especially when they are alone. It may be your daughter's way of physically comforting herself and releasing stress/tension. Just like some kids get to the point that they can't go to sleep without rocking, some kids begin to need/depend on this release. It is also very common in neglected or abused kids, especially in orphanages. They don't get much physical contact or comfort and this is one way to create those comfort feelings. (not that I'm suggesting your daughter is neglected.)
You might try to give her some extra time and attention... rock with her if you can. She may be experiencing some extra stress or going through a needy period and needs some extra help in calming and comforting. Help her remember that you can comfort her and give her physical contact, she doesn't have to do it herself. :)