How and why did bats and dolphins develop echolocation?
There are many conditions in which echolocation has evolved, and bats, dolphins, and even some birds (oilbirds) have evolved the ability to echolocate with different anatomical structures. Echolocation is a great example of convergent evolution, where a very similar feature is developed through very different stages in different taxa. Stephen Rossiter (from Queen Mary University of London) has uncovered that both bats and dolphins have similar mutations in a unique protein called "prestin", that increases hearing sensitivity. This could be a key step in developing the ability to echolocate. 

Before a fully fledged echolocation system developed, fossil odontocetes seem to have developed high frequency hearing and sound production structures (for more details see research by Travis Park, Erich M. G. Fitzgerald, Alistair R. Evans http://rsbl.royalsocietypublishing.org/content/12/4/20160060 DOI: 10.1098/rsbl.2016.0060).  

Instead of anatomical limitations (eyes on the side of the head) driving the development of echolocation, it seems to have evolved because it gives predators a competitive edge over visually oriented predators.