ב׳׳ה There are several passages in Zohar Hakadosh ואתחנן that are first makor for writing the shem Shakai on the outside of the mezuzah. In chelek gimel 266 A, it states: “when bad things (sheidim) draw close to a persons door, they lift up their head (since they are compared to a snake they have to “lift up their heads” to see it. -Ramaz) and see the holy name on the outside, that is Shakai, as it is crowned, and rules over all of them, they become fearful and run away. R’ Yitzchak asks, if so, why do you need the whole parsha, just have the name?! In answer, it is specifically when the name is “crowned” by the parsha(s) it is as a king who comes out flanked by his entire army... it is then when they fear him. Come and see that the name והיה is spelled from bottom up (the tziruf is not the order of Shem Havaya) so Shakai is on the outside corresponding to this name, והיה is on the inside while Shakai is on the outside. Thus a person is guarded from all sides, inside and out