The tradition of diplomatic immunity/sovereignty of the embassies is centuries old.  For a long time (and still in some countries) the only places a religious minority could worship is in an embassy.