If it is available to you, most service dog handlers have found that using the handicapped stall of a public restroom presents the most space for the comfort of both dog and handler.
If a handicap stall is not available, then most handlers will teach their dog to slide in to the regular size stall standing beside the toilet and the wall as you enter yourself and close the stall door, then either turn around in front of the toilet space to exit the stall facing forward or back out of the stall once you have finished and opened the door.
If a regular stall is too small for both you and your service dog to fit, and waiting for a handicap stall is not an option, then some handlers feel comfortable with asking their dog to down stay in front of the stall door with the dog’s head facing under the door, sliding the leash under the door so that they can hold onto the leash at all times and remain in full control of their dog.
It is definitely not recommended that you ask a passerby or stranger to hold your dog’s lead for you while you use the rest room. Many highly trained, irreplaceable service dogs have been stolen in this fashion by unscrupulous people. And it may put your service dog in another dangerous potentially life threatening situation.