How to resolve illegal targeting that was allowed?
The correct answer (since this appeared in a tournament setting) is to call a judge as soon as you notice. 

The judge is likely to act according to section 2.5 Game Play Error
— Game Rule Violation of this pdf: http://www.wizards.com/contentresources/wizards/wpn/main/documents/magic_the_gathering_infraction_procedure_guide_pdf2.pdf

If the error is discovered in a reasonable time frame one possibility outlined is a rollback of the game state. 

If the error is not discovered in a reasonable time frame (likely you scenario as a couple turns have passed) the judge can leave the game in its current state after resolving state based actions.

From my interpretation of the pdf, your dragon remains exiled in the Chained to the Rocks example, but in the pacifism example the pacifism would be removed.