Defecating and urinating are both functions that are controlled by ring-shaped muscles called sphincters. When your sphincters get the signal from your brain to relax, you are able to urinate or pass stool.
As explained by NHS surgeon Dr. Karan Rangarajan (via YouTube), the urinary sphincter is smaller and weaker when compared to the anal sphincter, and this has an effect on why you pee while pooping but rarely ever poop while peeing. “When you urinate, you can easily isolate the smaller and weaker external sphincters around the urethra without relaxing the entire pelvic floor or the anal sphincters,” explained the doctor. This is why you can urinate without feeling the need to have a bowel movement.
However, when you poop and your external anal sphincters relax, because they’re much stronger and larger, they end up decreasing some tension in the urinary sphincters too, shared Dr. Rangarajan. “So you can pee whilst you poo.” On a side note, did you know that controlling those muscles is something we learn as we age, after being toddlers with involuntary reflexes? As you grow and mature, you are able to hold your poop till you find a bathroom or hold in your pee till you make it home while on a commute. Speaking of holding in urine and stool, this is not recommended by experts and has health consequences, especially when done frequently.