Remind you with the phone itself in your way
Get a small loop, strap, or lanyard which can attach to your phone or otherwise hold it (such as in a small bag). When you enter the stall, hang or clip the phone/bag onto the lock, handle, or knob that you must use to exit.
- Forget phone.
- Exit restroom.
- Whoa, what's that thing on the door handle? Oh yeah, my phone.
- Leave with phone, not without.
Attach the phone to you securely
Get such a loop, strap, or lanyard, that can clip onto your pants or belt loop or attach to your wrist. Attach it before you sit down, either holding the phone to the side of your pants or in your pants pocket or in your hand, as convenient per attachment location.
You may also place the phone in a location that is secure from the perspective of being safe from falling into the toilet or onto the floor and not something easily missed, but which location wouldn't work in normal carrying/holding—for example, you can put it in your front pocket even if this is normally uncomfortable for you, or you could just place it inside your bunched up pants near your ankles. You could place it on your shirt and roll your shirt up around it (perhaps).
Remind you with something else in your way
Tie a string from your pants to the door handle or put any object in your way that would prevent you from leaving: a string hanging down across your path or any object at all hanging from the knob/latch.
I do this when I need to get gas in the car, but I can't do it right that moment: I place some random object behind my steering wheel, in front of my speedometer and other dials, such as an empty soda can. Anything that will make me go "what the heck is that doing there?" and suddenly remember... oh yeah, get gas. Whew, I'm so glad I remembered!
Get a bluetooth device that alerts when your phone leaves your presence
Many of the bluetooth fob-style devices that are intended to alert you when you left your wallet or keys behind, can also alert you (through the device itself making a tone) when your phone goes away from you.
I don't have time to really research this to give you a solid recommendation, but check out bluetooth tracking devices for an introduction to these kind of devices. I don't know if any on that page actually support this use case, but you can search for some.
I have read that they can be a little unreliable and make an alert when they shouldn't, or that they can have an unacceptable lag, but perhaps you can find a good one that fits your use case or you can live with any down sides because of the up side of not leaving your phone behind for very long or getting very far.