Its essentially a way to cleanse the soul of what it did in this world, through various methods, depending on the severity of the deeds done. For example, to illustrate from Tanya perek Ches:, first regarding the cleansing for unkosher food:
ועוד זאת במאכלות אסורות, שלכך נקראים בשם איסור
There is an additional aspect in the matter of forbidden foods, for
which reason they are called issur (“bound” and attached):
מפני שאף מי שאכל מאכל איסור בלא הודע, לשם שמים, לעבוד ה׳ בכח אכילה
ההיא
Even if one ate a forbidden food unwittingly and his intention in
eating was for the sake of heaven, i.e., in order to serve G‑d with
the energy derived from it;
(Had the food been permitted, the very act of eating for the sake of
heaven would suffice to extract the good from the evil of the food’s
vitality, as explained above. In this instance, however, forbidden
food was eaten for the sake of heaven.)
וגם פעל ועשה כן, וקרא והתפלל בכח אכילה ההיא
moreover, even if he actually carried out his intention, having
studied and prayed with the energy derived from that food;
(Again, had the food been permitted and the person studied and prayed
with the energy provided by the food, the energy would be elevated to
Sanctity. But because the food was forbidden —)
אין החיות שבה עולה ומתלבשת בתיבות התורה והתפלה כמו ההיתר
the vitality contained in it does not ascend or become clothed in the
words of Torah and prayer that he studies and prays with the energy of
that food as is the case with permitted foods,
מפני איסורה בידי הסטרא אחרא משלש קליפות הטמאות
because it is held captive in the power of the sitra achra of the
three unclean kelipot which do not permit the energy of the food to be
elevated to Sanctity.
ואפילו הוא איסור דרבנן, שחמורים דברי סופרים יותר מדברי תורה כו׳
This is so even if it is forbidden by reason of a Rabbinic
prohibition, for1 “the words i.e., the prohibitions of the Scribes are
even more stringent than the words of the Torah.”
ולכן, גם היצר הרע וכח המתאוה לדברים האסורים הוא שד משדין נוכראין, שהוא
יצר הרע של אומות העולם, שנפשותיהם משלש קליפות הטמאות
Therefore, the yetzer hara (evil impulse) and the force that lusts
after forbidden things is also2 “one of the non-Jewish demons,” which
is the yetzer hara of the nations, whose souls are derived from the
three unclean kelipot.
They therefore lust after forbidden matters, since the forbidden
matters, too, derive their energy from the three unclean kelipot.
מה שאין כן היצר הרע וכח המתאוה לדברים המותרים, למלאות תאותו, הוא שד
משדין יהודאין, לפי שיכול לחזור לקדושה כדלעיל
On the other hand, the evil impulse and the craving force after
permissible things even when done solely to satisfy one’s craving in
which case, as mentioned earlier, even the permissible matter descends
into the utter evil of the three unclean kelipot; still it is3 “one of
the Jewish demons”; it is, as it were, a Jewish evil impulse, for it
(the vitality of a permitted thing) can be reverted to holiness, as
was explained above.4
Since the food itself is permissible, therefore, though it was eaten
to satisfy bodily desire, it can still be elevated to holiness (when
the person returns to the study of Torah and the service of G‑d). The
yetzer hara for forbidden matters, however, is intrinsically
un-Jewish, i.e., essentially foreign to the Jew’s character. As
explained elsewhere, one acquires this “foreign” yetzer hara by
immersing himself in “permitted” pleasures. These so coarsen him that
he begins to lust after prohibited matters as well — a desire totally
unnatural for the Jew.
אך מכל מקום קודם שחזר לקדושה הוא סטרא אחרא וקליפה
Although the vitality of permitted foods eaten out of bodily desire
can revert to holiness through the person’s repentance, nevertheless,
before it has reverted to holiness it is sitra achra and kelipah,
וגם אחר כך הרשימו ממנו נשאר דבוק בגוף
and even afterwards (after the person repented and elevated the energy
of the food to holiness) a trace of it remains attached to the
person’s body,
להיות כי מכל מאכל ומשקה נעשה תיכף דם ובשר מבשרו
since each item of food and drink that one ingests immediately becomes
blood and flesh of his flesh.
Since the food which became his flesh and blood was evil at the time
of consumption — having been eaten for the sake of bodily pleasure — a
trace of the kelipah remains in the body even after the person has
repented and elevated the vitality of the food to holiness.
ולכן צריך הגוף לחיבוט הקבר, לנקותו ולטהרו מטומאתו שקיבל בהנאת עולם הזה
ותענוגיו, מטומאת קליפת נוגה ושדין יהודאין
That is why the body must undergo the “Purgatory of the Grave” (a specific punishment for the body5 ) in order to cleanse it and purify
it of the uncleanness which it had received from the enjoyment of
mundane things and pleasures, which are from the impurity of the
kelipat nogah and of the “Jewish demons” (i.e., the “Jewish yetzer
hara” which desires permitted matters);
אלא אם כן מי שלא נהנה מעולם הזה כל ימיו
unless one had never derived enjoyment from this world all his life
(i.e., either he actually derived no enjoyment, or his enjoyment was
not of this world, since all his actions were completely for the sake
of mitzvot and holiness),
כרבינו הקדוש
as was the case with Rabbeinu HaKadosh (Rabbi Judah the Prince, who
said at the time of his demise that he had had no enjoyment of this
world even to the extent of his “small finger”).
He who never derived pleasure from this world all his life need not
undergo the “Purgatory of the Grave.” However, anyone who has not
attained this level must undergo this punishment to purify his body of
the uncleanness received from the enjoyment of mundane pleasures.
basically, because that energy in the food was not able to be used for holiness, it was used for the "other side" (chas veshalom), so to rectify that the soul needs to go through a purification to get rid of all its impure desires (even if the food was kosher, but if it wasnt for the sake of heaven). Also for not studying torah:
We shall now learn what is necessary for the rectification of
permitted words not spoken for the sake of heaven.
ועל דברים בטלים בהיתר, כגון עם הארץ שאינו יכול ללמוד
As for innocent idle chatter, such as in the case of an ignoramus who
cannot study,
He who is able to study is constantly obligated to fulfill the
commandment of studying Torah; for him idle chatter is prohibited. For
the ignoramus, however, idle chatter may be permissible. But —
צריך לטהר נפשו מטומאה זו דקליפה זו על ידי גלגולה בכף הקלע, כמו שכתוב
בזהר, פרשת בשלח דף נ״ט
he must have his soul cleansed from the impurity of this kelipah,
through its being rolled in the “Hollow of a Sling,”6 as is stated in
the Zohar, Parshat Beshallach, p. 59.
This punishment is described7 as “being slung from one end of the
world to the other,” or “from Israel to other lands.” The meaning of
this is that the soul is flung from one extreme to the other: First it
is shown the truth and preciousness of holiness, and then it is
“slung” into and reminded of the thoughts and words it experienced
while in the physical world — a most painful experience for the soul.8
אבל לדיבורים אסורים, כמו ליצנות ולשון הרע וכיוצא בהם, שהן משלש קליפות
הטמאות לגמרי
But with regard to forbidden speech, such as scoffing and slander and
the like, which being prohibited stem from the three completely
unclean kelipot,
אין כף הקלע לבדו מועיל לטהר ולהעביר טומאתו מהנפש
the “Hollow of a Sling” (alone) does not suffice to cleanse and remove
the impurity of the soul,
רק צריכה לירד לגיהנם
but it (the soul) must descend into Gehinnom (Purgatory — which is a
greater punishment and thus more effective in cleansing the soul).
וכן מי שאפשר לו לעסוק בתורה ועוסק בדברים בטלים
So, too, with one who is able to engage in the study of Torah, but
occupies himself instead with idle chatter —
אין כף הקלע לבדו מועיל לנפשו למרקה ולזככה
the “Hollow of the Sling” alone cannot effectively scour and cleanse
his soul,
רק עונשים חמורים שמענישים על ביטול תורה בפרטות
but it must receive the severe penalties which are meted out for
neglect of the Torah in particular,
מלבד עונש הכללי לכל ביטול מצוות עשה מחמת עצלות, בגיהנם של שלג, כמבואר
במקום אחר
apart from the general retribution for the neglect of positive
commandments through indolence, namely the “Purgatory of Snow,” as is
explained elsewhere.9
The purgatory (Gehinnom), where the soul is cleansed of the “stains”
of sin so that it may enter Paradise to enjoy the radiance of G‑d’s
glory, operates on the principle of “measure for measure,” i.e.,
punishment in kind. Thus sins of commission caused by the heat of
passion and lust are cleansed in a “Gehinnom (nehar, lit., ”stream“)
of Fire,” while sins of omission, due to indolence and coolness (i.e.,
lack of fervor), are cleansed in a “Gehinnom of Snow.”10
וכן העוסק בחכמות אומות העולם בכלל דברים בטלים יחשב לענין עון ביטול
תורה, כמו שכתוב בהלכות תלמוד תורה
Occupying oneself with the sciences of the nations of the world is
likewise included in the category of engaging in inconsequential
matters insofar as the sin of neglecting the Torah is concerned, for
in studying the sciences of the nations, too, one is guilty of
neglecting Torah study, as is explained in the Laws of Torah Study.11
ועוד זאת, יתירה טומאתה של חכמת האומות על טומאת דברים בטלים
Moreover, the impurity of the science of the nations is greater than
the impurity of idle speech;
שאינו מלביש ומטמא רק המדות מיסוד הרוח הקדוש שבנפשו האלקית
for the latter clothe and defile only the emotions [which emanate]
from the holy element of ruach (Air) within his divine soul,
בטומאת קליפת נוגה שבדברים בטלים הבאים מיסוד הרוח הרע שבקליפה זו בנפשו
הבהמית, כדלעיל
[by tainting them] with the impurity of kelipat nogah contained in
idle speech (which is derived from the evil element of ruach (Air,
which is one of the components) of this kelipah in his animal soul),
as mentioned above.
The G‑dly soul and the animal soul are both composed of four spiritual
“elements”: Fire, Air, Water and Earth. The emotions, such as love and
fear, which one expresses in idle talk, emanate from the element of
Air. Thus, idle speech defiles the emotional attributes of the divine
soul, which emanate from the holy element of Air, by using them in the
service of the animal soul’s element of Air, i.e., its emotional
attributes — which are “impure”, since they derive from kelipat nogah.
ולא בחינות חב״ד שבנפשו, מאחר שהם דברי שטות ובורות
[Idle speech does] not, however, [defile] the levels of ChaBaD (the
intellectual faculties) in his soul, for it is but words of
foolishness and ignorance,
שגם השוטים ועמי הארץ יכולים לדבר כן
since even fools and ignoramuses can speak that way.
Since these are not intellectual matters, the intellect remains
uninvolved and untainted.
מה שאין כן בחכמת האומות הוא מלביש ומטמא בחינות חב״ד שבנפשו האלקית,
בטומאת קליפת נוגה שבחכמות אלו
Not so in the case of the science of the nations; thereby one clothes
and defiles his divine soul’s faculties of ChaBaD (intellect) with the
impurity of the kelipat nogah contained in those sciences,
שנפלו שמה בשבירת הכלים מבחינת אחוריים של חכמה דקדושה, כידוע ליודעי ח״ן
whither they (the sciences) have fallen, through the “shattering of
the vessels,” out of the “hinder-part” of Chochmah of holiness, as is
known to those familiar with the Esoteric Wisdom.
Thus the study of these sciences contaminates the intellectual
faculties of the G‑dly soul, and it is therefore much worse than idle
speech, which contaminates only the emotional faculties,
אלא אם כן עושה אותן קרדום לחתוך בהן, דהיינו כדי להתפרנס מהן בריוח
לעבוד ה׳
unless one employs them (these sciences) as a useful instrument, viz.,
as a means of earning a more affluent livelihood with which to be able
to serve G‑d,
או שיודע להשתמש בהן לעבודת ה׳ או לתורתו
or unless he knows how to apply them (the sciences) in the service of
G‑d or to his better understanding of His Torah; e.g., he utilizes
mathematics to better understand the laws of the Sanctification of the
New Moon.
וזהו טעמו של הרמב״ם ורמב״ן ז״ל וסיעתן שעסקו בהן
This is the reason why Maimonides and Nachmanides, of blessed memory,
and their peers, engaged in them (in the sciences — since they were
able to utilize this knowledge in the service of G‑d and Torah).
Regarding that which was stated at the beginning of this chapter that
a thing prohibited even by Rabbinic enactment remains attached to the
three unclean kelipot and cannot be elevated to holiness, even when it
is used unwittingly and for the sake of heaven (i.e., in order to have
strength to study and pray), — the following story is worth relating:
A chassid once came to the Alter Rebbe lamenting the fact that his
son-in-law was subject to periods when he would doubt his faith. The
Alter Rebbe responded that the son-in-law had unwittingly consumed
milk which was milked by a non-Jew, with no Jew in attendance. Though
he was unaware of this fact, and though the prohibition against such
milk is only of Rabbinic origin, this had so strong an effect upon him
that it caused him to doubt his faith. The Alter Rebbe then proceeded
to tell the chassid how the matter could be rectified, thereby healing
the son-in-law of his spiritual malady.
basically all different kinds of speech, not used for the sake of heaven (chas veshalom) have different effects on the soul, and commensurate with those effects does it need to be purified through various methods, as outlined above (each method is different)