The foundation for immersing on erev Shabbat is laid by the Zohar (Vayakhel 204b), which teaches that when Shabbat arrives the holy people must immerse themselves to shed the spirit of the weekday, because during the week another spirit — a spirit of the ordinary — wanders and rests upon the people, and one who wishes to depart from that spirit and enter into the higher, holy spirit must immerse so that the elevated holy spirit may rest upon him.
The Shulchan Arukh HaRav (Orach Chayim 260) codifies this as an l'chatchilah obligation, ruling that it is a mitzvah to wash one's entire body in hot water on erev Shabbat in honor of the day — giving the practice a firm halakhic footing alongside its mystical grounding.
The Zohar's teaching about shedding the weekday spirit is echoed spiritually by אלשיך, רות ג ג, whose passage draws on the same Zohar to describe how on Shabbat a flow of holiness descends and clothes the soul, ascending beyond its ordinary boundary — so that purification before Shabbat opens the person to receive that higher neshamah.
The Sefer HaChinukh (173) supplies the deeper spiritual logic that underlies the entire practice: immersion makes a person feel as though he is newly created at that moment, recalling the primordial state when the whole world was water, as written in Bereishit 1:2, and this sense of renewal is meant to prompt genuine inner transformation and rededication to the ways of God.
The Mishnah Berurah (260) adds a practical caution that those who are God-fearing should warn their communities: the mitzvah of bathing for Shabbat must not, through careless timing especially on short winter days, lead to the far more serious violation of Shabbat itself, including the Torah-level prohibition of combing one's hair afterward.