Zohar Hakodosh “ארבעים יום שירד המבול הם כענין מלקות ארבעים” – “The forty days that the rain of the mabul came down to this world, is like the forty malkos (lashes).” The mabul lasted for forty days, as it was like the world was receiving malkos, where one is given forty malkos. However, we need to understand this, for although the Torah says that there are forty malkos, Chazal tell us that it means only thirty-nine malkos. Thus, when one receives malkos, he only receives thirty-nine malkos. If the Mabul was a punishment of malkos, why didn’t it only come down for thirty-nine days? (שם משמואל)
The Maharal explains that there are forty parts to the soul of a person, and that is why the formation of a human takes forty days. There is one inner soul, and the other thirty-nine parts surround that one part, and make it complete. The innermost part can never directly become tamei, but if the other parts which surround it and are connected to it are tamei, then it too becomes tamei. When one sins, all forty parts become tamei; the thirty-nine parts actually become tamei, while the innermost one becomes tamei for it is connected to the ones which are tamei. However, when they become purified through the malkos, once there are thirty-nine malkos, those thirty-nine parts become tahor, and because they are tahor, the last one automatically becomes tahor. Thus, the Torah says there are forty malkos, for all forty parts of the nefesh are tamei and need to be purified. However, once the first thirty-nine become tahor, they are all tahor, and there is no need for the last malkah.
All of this only applies to Klal Yisroel; internally the Yid is good and pure. However, for the other nations of the world, even the innermost part of their soul is from the root of the nachash and is not pure. Thus, they actually need forty malkos to be purified, and there is no concept of thirty-nine in regard to them. Therefore, the mabul was forty days of rain, k’neged the forty malkos, for they need forty malkos – as thirty-nine would have not sufficed for them.
This explains what it says in Sanhedrin 58b that “גוי ששבת חייב מיתה” – a non-Jew who keeps Shabbos, is chayiv misah. The thirty-nine melochos which are prohibited to perform on Shabbos are k’neged the thirty-nine klolos, curses which came upon the world due to the sin of eating from the eitz hada’as. There were thirty-nine curses upon the world k’neged the thirty-nine parts of the soul of a person – for a person is a miniature world. There were only thirty-nine curses, for the innermost part is pure and cannot itself become tamei, and thus the world only received thirty-nine curses. On Shabbos, there are thirty-nine melochos which are prohibited, because Shabbos represents that innermost part of the soul, which remains pure. On Shabbos, there are only thirty-nine melochos, for it shows that on Shabbos Kodesh there is nothing which can infringe upon it – it remains pure. One can attach himself to Hashem, and the inner true person can be revealed. All this is in regard to Klal Yisroel. However, in regard to the other nations of the world, whose innermost part of their soul is from the nachash, it is better that this evil part of the soul not be revealed. Thus, a non-Jew who keeps Shabbos is revealing the innermost part of his soul, which is not pure, and is thus punishable by death.