HI, thanks for using healthcare magic
The fact that she can go days of being dry implies that she is physically capable so the instances where she may wet or stool herself are physically preventable because the toilet training ability is there.
This means that these episodes are emotionally/mentally related. You have already tried good techniques on your own to try and change this particular behavior - time outs and removing game privileges
These are good ideas and involving non physical punishment, you may want to consider a reward system along with this.
For example , each day without an incident would mean a pebble or rock or some other item is placed in a jar.
When a certain amount are collected (eg after 3 to 5 days or more), then a small reward is given.
It can be small eg going to park she likes, playing a game with parents, playing dress up etc. Best not money related.
You can choose a different type of reward system if you like.
If adding rewards does not work, then you should consider seeing a
psychologist to talk to her to see if there is an underlying issue.
I hope this helps