Is she having difficulties with school material? If so, it could be that she is leaving the classroom for stress reasons. To get away from it all.
or ti could be boredom?
Does she go at home a lot?
Nowadays there is a tendency to ascribe emotional problems to child behavior, before looking at other options. What many forget is that children are as complicated as adults. The daughter mentioned above was so clever at feigning illness that the school nurse thought I was a neglectful parent. She was an extremely clever child and more than a little devious. It didn't stop her from becoming a great adult.
I wish people would give a little more leeway to children. The sole measure of their development appears to be how well they do in school and how tractable they are. Poor kiddies! What I love is their enormous variety.
Good point by allmymarbles. I've had kids do the same thing with stomach aches.
One of my daughters was antsy and very bored at school. She had lots of ways of getting out of class. ("I have to go to the bathroom." "I have to throw up." "I want to go the the nurse's office. I am sick.") This might be true with your child.
My guess is that it is a sign of anxiety or of some kind of a bladder infection. If it only happens at school, then it is probably anxiety driven. Either way it is something worth looking into. How do you know that she uses the bathroom frequently? This is not something a kid discusses with the parent. Also did she have this problem last year?