The story of Janaka in hell or in the world of Yama is found in the Padma Purana. The story narrates the abandonment of the gross body by Videha Janaka by a yogic feat, whereupon a vimana (a divine conveyance) descended on the earth to take his self to heaven. On the way it stopped for a while in Yama’s realm, where sinners are chastised. Seeing Janaka in their midst, the sinners felt comforted.
Suddenly it occurred to Janaka that he ought to stay on in Yama’s realm if his presence satisfied the sinners there.
Janaka approached Kala and asked him for permission to stay with the sinners to give them warmth in their predicament. Kala suggested that Janaka could assure liberty to the sinners by transferring some of his merits to them. Janaka agreed and left for the world of the gods.
Janaka later inquired why he was made to stop in hell. To this Yama, replied that he would have to suffer for a while because he had once prevented a cow from grazing but that his good acts were so numerous that he deserved heaven.