I have the same experience and always assumed it was caused by bowel contents putting pressure on the urethra in/around the prostate. I'd be interested to learn if there's anything more to it than that and if it's a uniquely male experience.. (I assume you're male?)
I'm pretty sure the muscles are controlled by the same nerves/neural pathways. A lot of people can't shit without pissing also but once you have shat you don't need to hold those muscles so you can let loose. It's a bit like trying to wiggle your ring finger without moving your pinky or middle. Except with your dick.