When you have to urinate but it isn't convenient, your body has a complex system that lets you hold it in until it's safe to do so. This video explains how that mechanism works and just how safe it is to overwork that system. To oversimplify, you have a set of muscles in your pelvic floor that prevent your urinary tract from emptying until the brain decides that it's safe to do so. If your bladder isn't very full, you can consciously decide to keep this muscle closed, holding in your urine. However, as your bladder fills, pressure builds up, sending signals to your brain that things are getting serious. It starts with feeling pressure and eventually leads to pain. If your bladder gets too full when you're trying to hold it, your brain can override whatever conscious thoughts you might have about holding it in and release the floodgates, so to speak.
As we've discussed before, the brain is a pretty good judge of when you've held it too long. If you're holding it for just a short time, you're safe. However, frequently holding it can over stress those muscles in your pelvic floor. Over time, this could cause them to fail, leading to a variety of problems when you're older like urinary incontinence or an overactive pelvic floor. So, if you have to urinate and you have the option of going, do your future self a favour and just take the bathroom break.