Baptism stems from the ancient practice of the tevillah service, during which either persons or things are immersed in a mikvah (a bath), for various purposes and intents. It is not so much to be cleaned physically, because in most cases one must become spiritually clean before participating. It is rooted very deeply in His people Israel from many centuries before either John the Baptist or Jesus ever appeared on the eschatological scene.
The general principle comes to us from Leviticus 22:6 where the Torah implies that that which is unclean must be washed with water. This was why the Israelites always required full body immersion in either a mikvah or body of “living water” by any who wished to convert their cobenant. Through such an initiatory process a gentile could be allowed into the community of faith. This not only washed away their ceremonial uncleanness, but also represented a death to their old life and a rebirth into a new one. Much like Christianity, the waters are prayed over and sanctified/ They were consecrated for this purpose, with the Lord overseeing. This bestowed the necessary blessings whereby He sanctified the individual recipient.
So baptism, or immersion, was required in many other instances. The priests not only had to be immersed before Yom Kippur and the other yearly festivals, but the High Priest had to also be immersed after sending off the scape-goat (the azazel). Many individuals also practiced ritual immersion in preparation for Shabbat. If one wanted to dedicate themselves to service, such as in the case of a Nazarite, they also had to be immersed as a sign of intended repentance. They would be reckoned as dead to their old life, and for the time of their vow they lived in a newness of life. Then finally (but not exclusively as you will see) there is the taharah (purification) service, or the washing of the dead for burial.
So because of all this, Rabbi Aryeh Kaplan, in his book, Waters of Eden (Mesorah Publications, 1993) describes this practice in Israel preceding at least Hillel (100 B.C.) and that this immersion in a mikvah is a type of womb as well as a type of tomb. The waters of life are reminiscent of Creation where the waters above separated from the waters below brought forth the ground from which Adam was made, and then again Eden itself, surrounded by waters. In Israel brides and grooms were immersed symbolizing the newness of life they will share as one. These are all great times of transformation, rebirth, elevation into a higher order, consecration into a Holy purpose, and so on.
In Mikvah: The Art of Transition (found at Chabad.org), scholar Avraham Trugman tells us they baptized “in order to become ritually pure after a temporary state of ritual impurity, or when a person or object changes status”:…! The same rule applies even when textiles, instruments, or vessels, were dedicated to use by the Lord. These all had to be passed through the waters of purification. When immersed in living waters (consecrated, blessed waters) life “swallows up death.” The status of that object or person from God’s standpoint has been changed.