It is also known as an internal allusion, a literary device that helps give structure to the piece of writing.
Callbacks are a subset of inside jokes which refer to something told in the set rather than to anything in general.
In television, the term callback has come to mean a joke or line that refers to a previous episode (or sometimes, in rare cases, movies).
Seinfeld, a show built around stand-up comedy, regularly used callbacks in its scripts; its use of the strategy commonly kept the callbacks confined to events in the same episodes, having the effect of bringing the episode full-circle or creating an ironic twist ending.
Another series, 30 Rock, employed callbacks to reference fictitious movies and television programs created within the show.