It was punishment for the actions of the evil in question, who even while imprisoned could not understand it. He assumed they were just keeping him away because they were jealous, rather than he doing something wrong. They didn't kill him because he still had a chance to Heel-Face Turn.
The Precursors were incapable of killing the Ultimate Evil, but were certain that their descendants would, so they kept it sealed away until their technology was advanced enough that their people could easily deal with the evil being.
The Ultimate Evil refuses to come out; he likes it better in his can. The current Big Bad forces him out as part of her plan to rule the world; the Ultimate Evil decides to destroy all of existence in revenge for having his nap interrupted.
The Ultimate Evil isn't as powerful as he used to be because the years of imprisonment have weakened him. Once he regains his strength, he's ready to wreak vengeance on the world for his years of being trapped.
The Ultimate Evil disagrees that he owes the Big Bad a favor, but he has an agenda of his own and is still a threat to the world.
Parodied: The can the Ultimate Evil is sealed in is a Campbell's Soup can, label and all.
Zig Zagged: The Ultimate Evil is unsealed, but it turns out it was a perfectly innocent being driven mad by its imprisonment; a Cooldown Hug mixed with some Epiphany Therapy is all it takes to stop its Roaring Rampage of Revenge. Then it turns out that it was sealed because it had omnipotence but no concept of right and wrong; now that it's been cured of its insanity, it's back to warping realityfor kicks and giggles. Someone takes advantage of its childish nature, though, and manages to distract and seemingly tame it by teaching it to play a game. Then it starts rewriting reality into a colossal version of said game...
Enforced: "We need to explain why the villain hasn't attempted to avenge himself on the kingdom before, so we had to have him escape from a magical prison built specifically for him."
Lampshaded: "And, like a hundred other things, the Ancients leave us a really huge problem they could've fixed the first time around."
The Ultimate Evil made sure he couldn't be destroyed by the Ancients by sealing himself in a can, confident that he would be awakened in the future long after his enemies had all died off.
Alternately: The Ultimate Evil succeeds in destroying civilization. Then he seals himself in a can so he doesn't get bored waiting for another civilization to destroy.
The Ancients deal with an immeasurably powerful villain by sealing him away in hopes that someone will be able to destroy him for good should he escape in the future.
Exploited: The Ancients dealt with all their enemies by sealing them away; the current Big Bad collects sealed evils and releases them. He recruits some of them, and sends the more ambitious or incompetent ones at the heroes to distract them from his real plans.
The Ancients not only sealed away the Ultimate Evil, they also made sure he could never come back, possibly by launching him into the sun.
The Ultimate Evil kills the Precursors before they manage to imprison him.
The Precursors don't even bother with sealing the Ultimate Evil away and instead opt to outright kill him.
Discussed: "I thought only in bad sci-fi stories would there be Precursors worthy of the name so utterly stupid as to leave their enemies imprisoned, rather than actually eliminate the problem, but these guys really were both that powerful and that stupid. Well, I'm suitably impressed."
Conversed: "Why do they always 'seal away' these Ultimate Evils in these shows? Couldn't they, just once, kill the guy and be done with it?"
Reconstructed: The being in there had very little empathy. Although it wasn't evil, it still could very easily commit acts of horror without remorse. It was sealed so it would start thinking of others when it had only itself as company. Although it didn't remove the tendencies, it did give it a better chance for a Heel-Face Turn due to the time spent in.