How come semen randomly leaks out after masturbation?

It shouldn't. If you ejaculate after masturbation, the fluid should be completely expelled until you next encounter. You may be leaking fluid from a gland in the urethra; this is commonly referred to as pre-cum. Or, you may have a blockage in your reproductive tract that causes fluid to leak out more slowly as it liquefies.