Why did the urinary bladder evolve?
Here are just a few points that might apply:


Urine is used for scent marking by some species, so the ability to store urine could be useful.  
At the opposite side, controlling the release of a strong scent would help in stealth for both predators and prey.  (In addition, a single strong scent might temporarily overload a predator's sense of smell making tracking more subtle scents more difficult.)
Flushing an excretion point (single point reduces opportunities for invasion) under some pressure could help avoid blockage and parasitic invasion/accumulation.  (Providing a tube from the extraction organ to the excretion point allows more flexible (and protected) placement of the organ, but also increasing the benefit of a flushing mechanism.)
Flushing could also reduce contact with skin. Urine might act as an irritant and a nutrient source for parasites.
Adding a buffer is a common technique for any pipelined operation to allow smaller resources to handle temporal variation in input and output rate.  Without a such a buffer, all stages have to be sized for the maximum utilization rather than something closer to average utilization.
Avoiding potential contamination of food and water may also be a benefit of controlled urination (or excreting might have a fertilizing or pest-deterrent aspect for plants).


Since terrestrial animals presumably retained urinary bladders developed by their marine ancestors, benefits associated with terrestrial lifestyle would only provide selective pressure to retain such a feature. However, if somehow a line of terrestrial animals abandoned urinary bladders, it is not entirely implausible that even scent marking benefits could increase the selective pressure enough to overcome some peculiar opposing selective pressure.

Initially, the animal might apply scents by scratching at an area of skin irritated by urine release against some surface. Then this scratching might be preferentially located (i.e., a scent marking behavior is developed). Having such a behavior would then obvious bring benefits to storing a significant amount of urine and eventually to being able to squirt the urine (allowing the scratching behavior to fall away).

The above are just somewhat reasonable speculations about what selective pressures might encourage the development (and retention) of a urinary bladder.  Hopefully, someone with actual knowledge will provide a better answer documenting established theory and evidence for how urinary bladders actually developed.