The story goes that the guy got lost inside the mosque and ended up in some really funny situations trying to find his way out. Also, he had some comical interactions with the people there who were trying to help him.
Well, in this story, the boy came up with a brilliant plan to deceive the Yama King. Maybe he tricked the king into believing something that wasn't true or found a loophole in the king's rules.
The king's lost finger might have led to a series of challenges and power shifts. As for the slave, their fate could be intertwined with the king's misfortune.