My younger sister (now in her 30's) used to do this often. It sounds so simple, but it turned out she had to go #1. We would sit her on the toilet and let her use it and she would calm down and go right back to bed and sleep. Hope this helps. (It did take us several episodes to know what was going on though. She was in such distress. I am just six years older than her and I was the one to figure it out, just on a whim.)
Okay... I know it's several days after you posted this, but nobody's answered and I just came across it now.
Don't panic... Upon reading what you described, my first thought is... your kid might have epilepsy. All those strange things she's doing .. that could be a seizure. Many people only know about the generalized seizures (entire brain misfiring briefly) where a person will fall down and shake or simply become unaware of their surroundings and stare off into space. Truth is that partial seizures (a section of the brain misfiring briefly) are more common. People just don't recognize them since they're not the drama or obviousness of the generalized seizures. Sometimes they go undiagnosed forever if nobody notices and it has no impact on their day to day lives..
Anyway..
Here are the two reasons why epilepsy is the first thing I thought of with what you described:
1. When the brain is transitioning from being awake and is shifting gears into the different phases of sleep.. This is a very, very common time for epileptic people to have seizures.
2. You described behavior that's odd for her. I don't know if you are aware, but much of it really is in keeping with what typically happens to some people when they're experiencing a partial seizure. So the stuff you mentioned like:
Sudden difficulty in communicating for a brief period
Repeated movements, oftentimes ones that seem weird or aimless or like they're automatically doing it are common indications that someone is having a seizure
The mouth doing strange things is extremely common in seizures. Stuff like smacking or clicking or other sounds, chewing or biting or licking. Weird eye stuff is common too. Like rhythmic blinking or eye movements.
Things like repeating words, regardless of whether they make sense or form a sentence or even legit words.
Tugging at clothing or blankets or whatever is near, even picking at the air
Repeatedly standing just to sit back down or pacing the same path over and over
Afterward it is common for the person to super tired and be quite confused for a while. Loss of bladder control is not uncommon. They may have zero memory of what just happened.
If you think it may be seizures, make an appointment with her doctor. Keep detailed notes each time this happens so the doc has as much info as possible to work with. Tell the doc if there's any family history of seizures or if she's had any brain injuries like a concussion or a serious lack or oxygen before. Take note of stuff like when it happened, how long it lasted, if movements were on a specific side of the body, how well she could communicate, what she was like after.
I really, really hope she's just having weird *** dreams, and that this will just go away, but my first thought was that it's seizures. If it is epilepsy, just know that a LOT of the geniuses we can name today had epilepsy. Tons of healthy and happy people have it and lead fulfilling lives. In most cases it need not be a life limiting factor. Not at all.
I do apologize for the length of this response, and I truly hope things go smoothly for the little one and for you as well.