This is as closest I’ve found to a Disney-sanctioned position on leaving and reentering queues in order to go to the toilet:
The answer to your question is that there is no official way to leave your spot in line to run to
use the restroom. If you have a family member with you, and they can hold your spot in line, most people won't have any problem if you scoot out for a few minutes and hop back in place. If you are by yourself, however, it can be up to the people in line behind you to allow you to return to your spot.
My suggestions are to definitely use the restroom prior to hopping in the queue for an attraction. Most lines are not that long, so you probably won't need to use the restroom. Also, if you can take advantage of the new
Genie+ Lightning Lanes, you can schedule using the bathroom outside of your return window for an attraction.
If all else fails, definitely ask the people behind you if they would mind if you stepped away from your place for just a few minutes. You can use your
My Disney Experience app to find the restroom located nearest the attraction, and that will help cut down on the time you step away.