This is something we can't really know. The first words of the Kaddish are adapted from a verse of the Book of Ezekiel (38:23). The core of the Kaddish, the response, "May His great name be blessed forever and ever and ever," is similar to several verses in Tanakh. At some point it became a popular way to respond in a setting of public prayer. The Talmud and contemporary works describe this response as common custom almost two thousand years ago. But just because that's the earliest mention, doesn't mean that's when it began.

The ancient Targum Yerushalmi on the Torah, also composed in Talmudic times, dates the custom back to Jacob and his sons. It describes how Jacob called his sons to speak his final parting words. He wanted to reveal to them the end of days, but he saw that from heaven he was being prevented from doing so. He thought, "Perhaps one of my children is unfit" and he confronted his sons with this. He said to them, "Perhaps one of you has broken away from his brothers in his heart and wishes to part ways to worship other gods?"

The sons of Jacob all answered as one, "Hear O Israel, The L-rd is our G‑d, the L-rd is One."

And Jacob answered, "May His great name be blessed forever and ever and ever."

Most likely, over the years different customs arose and became formalized, adding context and substance around this standard congregational response until it reached the form we know as "Kaddish". The oldest version of the Kaddish is that found in the prayer book of Rav Amram Gaon of the 9th century—but that doesn't tell us much, either, since we have no knowledge of any Jewish prayer book written before that. People back then didn't write down things that were common custom and well known to all, like well-known prayers and everyday rituals. They knew them by memory and saw no need to record them. After all, parchment was an expensive commodity.

The earliest text that makes a connection between the prayers of a child and and the plight of the deceased is the circa 3rd century midrashic work, Tanna D'bei Eliyahu. There is recounted a story very similar to the story included here about Rabbi Akiva, but involving Rabbi Yochanan Ben Zakkai, a 1st century sage:

Rabbi Yochanan ben Zakkai told:

Once I was walking on the way and I found a man who was collecting wood. I spoke to him but he would not say a word back to me. Only later he came to me and said, "Rebbe, I am dead, not alive."

I replied, "So if you are dead, why do you need all that wood?"

He answered, "Rebbe, listen to me and I will explain. When I was alive, my friend and I would spend our days sinning at my estate. So when we came here, they sentenced us to burning. I collect wood and I burn my friend. Then he collects wood and he burns me."

So I asked him, "Did they tell you how long your sentence is?"

To which he replied, "When I came here, I left my wife pregnant. I know that she is carrying a son. So I am asking you, please take care of him from the time he is born until he will be five years old. Take him to a school to learn to read and pray. For at the time that he will say, 'Blessed is G_d Who is blessed!' they will raise me from the judgment of Gehinom."

From this story and the story of Rabbi Akiva it seems that it was taken for granted that a child's prayers can help his deceased parent. But when did it become customary for an orphan or mourner to say the Kaddish?

The earliest mention we know of is in the 12th century work, "Sefer HaRokeach" of Rabbi Elazar of Germany. The 13th century "Ohr Zarua" of Rabbi Yitzchaak ben Moshe of Vienna mentions that in Germany and the Slavic Lands (which he calls "Canaan") they have this custom, but in France they did not. And in the 11th century "Vitry Machzor" composed by students of Rashi (Rabbi Shlomo Yitzchaki) in France, there is also no mention of it.

Does this mean that the custom arose at that time in Germany and the Slavic lands and spread from there? The fact that the custom is just as prevalent among non-European Jews makes this difficult to accept. It is very rare that the Jews of North Africa and the Middle East would accept a custom peculiar to European Jews. Perhaps it was long a common custom in many lands but the French just never got into it. Again, we cannot really know.

Does the fact that earlier codifiers such as Maimonides and Alfasi do not mention the recitation of the Kaddish by a mourner mean that it had not yet become a custom in their land? Not necessarily. They generally only mention those things that are obligated from the Talmud. Saying the Kaddish for a deceased parent may have arisen in a more grassroots fashion. Or perhaps it was just so well known that the authors of the Talmud did not feel a need to mention it and the later codifiers just followed suit.

Whatever the history is, reciting the Mourners' Kaddish became a universal custom among Jews in every land. The rule of thumb is that when the Jewish People as a whole agree upon a single custom (quite a miracle in itself), that custom becomes a law just as precious and just as stringent as one given to Moses by G_d at Sinai—and even more so. A parent, even one who is a great artist or inventor, will always cherish the creative works of his child more than his own. So, too, the G_d of Israel cherishes the customs His people have created in His name more than any of the laws that He has given us.