Hi babypup.
My DD was in Y6 when she developed exactly what you are describing.
I honestly can't remember exactly how long it lasted - maybe four months or so but it might have been longer.
It got a lot worse before it got better, and I remember my DH and I being desperately worried. We sat up in bed one night talking about how this would going to have such a negative impact on her whole life..we ended up in tears worrying what on earth we could do to help her. I thought she would have it for life.
She's at college now, and tbh, I'd forgotten about it and haven't thought about it for years until I read your post.
One thing I would say about my DD is that she was having a particularly stressful and difficult year, and I'm 100% sure it was stress related.
I am also convinced that the fact that she bottled things up and preferred not to talk about things facilitated it happening, iyswim.
In the end I think it was comforting to her to do it, it was like a distraction and she said that although she couldn't help it, it felt nice and she liked it happening.
She only told me this afterwards, when it wasn't happening anymore, but on another occasion, she gave me the impression that she was choosing to do it, and didn't want to stop. so I'm not sure if sometimes she chose to do it, but at other times she couldn't control it.
Not sure if that helps. Try not to worry. Can you recognise a pattern of when it happens and/or when it goes away?
Does your DC seem withdrawn/unhappy/distressed at the time that it flares up again? With my DD, from the time it started, to the time it stopped it was happening all the time, within that period, it didn't come and go, iyswim, and once it had stopped, it never happened again.