Rav Huna says that the children of Israel wandered in the wilderness for forty years because they didn’t follow the words of God. Because of their sins, the old generation had to die in the wilderness during the forty years, before coming to the ‘Promised Land’.
Mashiach will lead the people through forty years of the cleansing process. During this time of wars, pain, and death, some would be cleansed and all wicked would be removed before arriving at the time of the Resurrection.
When the dead rise to immortality, the Light from the upper levels would flow continuously to this world as it says in Zechariah 14:9
“וְהָיָה יְהוָה לְמֶלֶךְ עַל כָּל הָאָרֶץ בַּיּוֹם הַהוּא יִהְיֶה יְהוָה אֶחָד וּשְׁמוֹ אֶחָד.”
“And YHVH will be king over all the earth; in that day YHVH will be one, and His name one.”
The word for ‘his name’ ‘שְׁמוֹ’ has the numerical value 346 as for ‘רצון’ and ‘צנור’ ‘his will’, ‘Pipe/Channel’. When the Light flows continuously to our world that was created with the ‘will’ of the Creator, there will be no more separation between the Light and the vessel, Malchut.
For a full revelation of Light we need a pure vessel and for that reason, a process of 40 years is required.
Moses went up to Mount Sinai to be with God for 40 days and nights before he could receive the Torah. Moses had the pure vessel that allowed him to receive and bring down the Torah but when he came down and saw the corruption of the Golden Calf, the Tablets broke down because the ‘vessel’ of the nation was not pure enough to receive the Torah.
The Second Torah that Moses received was on a lower level that fit the spiritual state of the people. It was made as a guide for soul correction and purification. After the coming of Mashiach, a new Torah will be revealed to match the Light at that time.
A Mikveh for spiritual purification requires a measure of at least 40 Se’ah (Old unit measure of volume)
The Flood was going on for 40 days and 40 nights to cleanse the earth.
Goliath the Philistine threatened the army of Israel for 40 days until he was killed by King David.
King David reigned for 40 years.
Forty days before a baby is conceived, heavens announce the matching spouse for the new soul.