One of the earliest Talmudic sources which deals with the Kaddish prayer directly associates the recitation of Kaddish with the mourners and makes the point that the Kaddish alleviates the judgment of the wicked. The following story is told about Rabbi Akiva and is often quoted in Halachic works:

R. Akiva went to a certain place (a cemetery) where he met a man (the soul of a man) carrying a heavy load on his shoulder with which he was unable to proceed, and he was crying and groaning. He asked him, ‘What did you do [in your lifetime]?’ He replied, ‘There is no forbidden act in the world which I left undone, and now guards have been set over me who do not allow me to rest.’ R. Akiva asked him, ‘Have you left a son?’ He answered, ‘By your life! do not detain me because I fear the angels who beat me with fiery lashes and say to me, “Why do you not walk quickly?”.’ R. Akiva said to him, ‘Tell me, whom have you left?’ He replied, ‘I have left behind my wife who was pregnant.’ R. Akiva then proceeded to that city and inquired, ‘Where is the son of So-and-so?’ [The inhabitants] replied, ‘May the memory of that wicked person be uprooted.’ He asked them the reason, and they said, ‘He robbed and preyed upon people and caused them suffering; what is more, he violated a betrothed girl on the Day of Atonement.’ He made his way to the house and found the wife about to be delivered of a child. He waited until she gave birth to [a son], circumcised him and, when he grew up, took him to the Synagogue to join in public worship [the recitation of the Kaddish]. Later R. Akiva returned to that [cemetery] and [the departed soul] appeared to him and said, ‘May your mind be [always] at rest because you have set my mind at rest1.’

Rabbi Akiva made the effort to train the child so that he would say Kaddish for his father. Through his efforts a man who had been cast to the depths of punishment was spared.

Now, why is it that we use the same Kaddish text when we want to raise the sublime Tzaddik to the loftiest supernal worlds and when we want to spare the lowly sinner from purgatory?

The explanation is as follows.

When we recite Kaddish — no matter for whom — even when it is for one who really needs to be saved from punishment, our intention in reciting Kaddish is to cause an elevation of the soul, in the greatest measure, to the highest levels of the Garden of Eden, similar to the process we initiate for the Tzaddik. The difference is that the Tzaddik is able to rise immediately and quite openly while for others it is a delayed process. The accomplishment of the Kaddish remains concealed and does not effect the ascent until after eleven months, when the period of judgment is concluded.