Poetic justice

The random but appropriate receiving of rewards or punishments by those who deserve them.

It was poetic justice when the man lost the money that he had got illegally.