Why do mammals have to get rid of NH4+ through the urea cycle?
Because they’re terrestrial animals. Fish get rid of ammonia by just excreting it ‘as is’. But ammonia is toxic in low concentration, so it is expelled with large volumes of water. Fish drink and piss continuously – you just don’t see it (actually, there’s a difference in sea and river fish because of salts and homeostasis) If land animals were to excrete ammonia, they would never have left the river banks. But urea is toxic only at higher concentrations and can be expelled with a smaller volume of water. Turning ammonia into urea is costly, but allows to save water and ultimately beneficial. Turning ammonia do uric acid is IIRC twice the cost in terms of energy, but since uric acid is next to insoluble it can be excreted without water (it’s the white part of bird droppings). This is the case of birds, and in this case it’s not so much a case of living close to water as of sparing the extra weight in water that is needed to make the concentration of urea non-toxic.