One night, a person saw a dream and he saw a beautiful girl in it. He was feeling very happy to have her company, he wants to do the act with her, but he then thought, she is not his wife and if he do adultery with her, he will be punished in the Hereafter.
So, he left her, moments later he woke up and found, he was dreaming of that girl, then he felt so sorry, why he left her, why he did not sleep with her, why he did not enjoy her body. Because he thought, if he had performed sinful act with her in a dream, God would not punish him in hereafter.
After a while, he thought, that was a dream, he did not do something there and now he is repenting here.
So, he thought, this life could also be a dream and things we are doing here can also make us repent when we finally woke up in the next world.
This way, he realized, if some act in dream can make him repent in this world, then his acts in this world can also make him repent in next world.
This world is just a dream, it will just vanish when people will woke up in Hereafter and say.
Woe to us! Who woke us up from our place of sleep.
Prophet (sws) also said.
Sleep is a sister of Death.