Animate Dead works in two steps: first, its enters-the-battlefield triggered ability returns a creature card from a graveyard to the battlefield, and then the Aura enchants that creature. While the creature is on the battlefield, Animate Dead sits on it as an Aura and applies its continuous effects (giving the creature -1/-0 and removing its abilities).
If the enchanted creature later leaves the battlefield for any reason — it's destroyed, exiled, bounced, or sacrificed — Animate Dead suddenly has no legal object to enchant. Under CR 704.5n, a local enchantment (Aura) that is not attached to the correct type of permanent is put into its owner's graveyard as a state-based action. Animate Dead goes to the graveyard at the very next state-based action check.
Importantly, this does not trigger Animate Dead's leaves-the-battlefield ability a second time in a way that re-animates anything. The enchantment simply ceases to exist; the creature card that just left the battlefield stays wherever it went (usually the graveyard), and no new return effect is generated.
Concrete example: You cast Animate Dead targeting a Gravedigger in your graveyard. Gravedigger returns to the battlefield enchanted by Animate Dead. Your opponent then casts Swords to Plowshares on Gravedigger, exiling it. State-based actions are checked: Animate Dead is an Aura attached to nothing, so it goes to your graveyard. Gravedigger remains exiled; Animate Dead is simply gone.
Relevant rules: CR 303.4c (Aura must remain attached to a legal permanent or it's put in the graveyard), CR 704.5n (state-based action for unattached Auras), and CR 704.3 (state-based actions are checked continuously).
Unofficial fan resource — not affiliated with or endorsed by Wizards of the Coast. Answers are AI-generated estimates grounded in the Comprehensive Rules and are not a substitute for an official judge. Verify anything match-critical.