>>26521558AZ was the ancient king of Kalos. His one Pokemon partner, a Floette, fought for Kalos in a war between it and another region. As the war went on with no end in sight, all that returned was a small box with a wilted flower in it.
AZ, filled with grief, used his position of power to make his people build a machine capable of raising the dead and granting eternal "life". He used this so he and his Floette could be together forever.
AZ, filled with rage, had the machine converted into a weapon capable of bringing great "death". He used this machine to rain destruction on the nation that Kalos was at war with and who took his one true partner away, ending the war in one fell swoop.
However, while he brought back Floette and had his revenge on those who took it away from him, Floette knew the truth behind the machine--it was powered by taking the life force away from other living beings, and many had died to bring it back. Because of this unspeakable crime, it left him.
Since then, the immortal king AZ wandered the world for three thousand years, searching for his Floette, hoping that one day it would forgive him and return. And realizing his mistakes, he kept the key to the weapon with him at all times, so it may never be misused again.
It's pretty clearly laid out in the game.