Agreed on talking to the doctor, but I just have to share a story this reminded me of. Might be a suggestion in there for you; might not.
Who knows what things are cross applicable?
I used to have a lady taking the lesson before me who was having a difficult time with her horse and had come to the trainer for help to work through this. Basically, she was fine as long as things were absolutely fine. One spook, look, slight equine brain fart, whatever (and he was Arab), and she would freeze and lose all capacity to ride. Definitely mental aspects (again, I’m NOT cross-applying that to your case. I realize your issue is most likely purely physically caused; hers originally was not). The horse, when his rider froze in terror, would of course realize that there must be truly terrible horse-eating monsters afoot, so he would bolt, she’d clutch and close her eyes, and eventually, she’d be dumped.
And she’d pee her pants. Always during the bolt-freak out. No other time, but she’d pick herself up from the dirt every time with her breeches (and her saddle) wet and would be cursing a blue streak. She just couldn’t hold it at the moment of “frantic blast-off gallop.”
My trainer was working with her in an indoor, trying to teach her to keep her mind engaged, doing things like “practice spooking,” first at a walk, etc. Even tried programming in a verbal cue - “Oh, SHIT!” - which meant that she should assume a specific riding position - legs down, sitting up straight, seat deep, etc. It was interesting hearing the sound effects as I groomed and saddled down the aisle from the arena. Hearing her lesson went something like, “Oh, SHIT. GOOD. That’s it exactly. That’s what you do. Okay, minor spook coming up. Oh, SHIT! Excellent. Good job. Now let’s . . . Oh, SHIT! SHIT! You know what to do! Sit up! SHIT! SHIT!! Don’t give up and fall off” Thud! “DAMN IT, I peed my pants!!!”
Anyway, one day, the lady showed up for a lesson in full Depends - not that anybody would have noticed if she hadn’t assumed that we all had noticed and explained. They really were discreet and hard to see, even under breeches. But she’d decided that even if she fell off each lesson, she could at least stop peeing all over her breeches and saddle and having to get back on like that.
She got on that day and even told the horse, “Okay, horse, you are NOT going to make me pee all over my breeches and saddle today. I don’t care WHAT you do. You CAN’T make me. So there.”
That day, with the embarrassment prospect replaced with determination, she rode much better, stayed on longer when he did bolt, and bounced right up afterward with a grin and dry breeches. The horse was stunned. All of the signals she’d been giving him of “Houston, we have a PROBLEM” were gone. He only bolted a few more times, and she rode him much better. And the couple of times that an “accident” happened, she would smile and be proud that she didn’t have to clean her saddle or breeches right away when she got home.
For her, moving that aspect of her problems (again, I realize there were other problems, and I’m not saying you have others, but the psychological aspect of this one clearly became a biggie, both for her and eventually for her horse) from embarrassment and worrying about it to “go ahead, this issue won’t interfere with my ride anyway, so there” made a huge difference in relaxation for her and by extension the horse. They were a mutually much more comfortable team.
Just a story. Take from it - or not - anything that might - or might not - apply.
And do talk to a doctor.