In modern literature,[1] it is often accompanied by an ironic twist of fate related to the character's own action, hence the name "poetic irony".
[2] English drama critic Thomas Rymer coined the phrase in The Tragedies of the Last Age Consider'd (1678) to describe how a work should inspire proper moral behaviour in its audience by illustrating the triumph of good over evil.
The demand for poetic justice is consistent in Classical authorities and shows up in Horace, Plutarch, and Quintillian, so Rymer's phrasing is a reflection of a commonplace.
Philip Sidney, in The Defence of Poesy (1595), argued that poetic justice was, in fact, the reason that fiction should be allowed in a civilized nation.
[3] When Restoration comedy, in particular, flouted poetic justice by rewarding libertines and punishing dull-witted moralists, there was a backlash in favor of drama, in particular, of more strict moral correspondence.