Poetic justice
From Conservapedia
Poetic justice is an outcome in which evil is punished in an ironic and unexpected way, or good is likewise rewarded.
The word karma is sometimes used as a synonym, mainly among people who are irreligious.