Why are lavatories located near the exits of an airplane?
There could be numerous reasons, 

Putting them near the galley centralizes non seat related things. It also allows you to run less piping as you can pump the same water to the sink in the lav as you would to the galley. 

They may be located in a place where a tank can easily be fitted beneath them so as to minimize the amount of piping needed from unit to holding tank. 

They are generally a convenient way to segment cabins as they provide an inherent wall (think between first and coach).  

As for an emergency situation, Lav doors can generally be locked from the outside (I have seen the little metal flap above the slide often opens and allows you operate the slide). Its common place to do this prior to takeoff and landing. I would think its part of the emergency decent checklist as well so as to keep them shut. There is a discussion on it here.