In males, the urethral opening serves as an outlet for both urine and sperm. The vast differentias that carry the sperms from the testes join the urethra, and there is the common opening. Under normal circumstances, due to the pressure created during micturition, the sperms are not allowed entry into the urethra during the act of urination. Similarly, during sexual excitement, the urethra serves as the passage for sperms and not the urine. There are no valves and rarely, some amount of intermingling may be possible.
Due to the push and pull during sexual intercourse or masturbation, the urinary bladder may feel the extra pressure and hence the feeling of urination. This is absolutely normal and there is no harm if one passes urine following masturbation or sexual intercourse. In fact, people with propensity for urinary infection are advised to avoid urinating immediately after the act to reduce the chances of UTI.