The supertrope of Death by Secret Identity
and Cartwright Curse
When something happens that would break the status quo of a show if a character were to remain alive, then the character conveniently (though often tragically) dies. Learning a secret identity is often one example of this, but there are others.
Some examples on Cartwright Curse
could go here. For instance on Doctor Who
if the Doctor offers to have someone travel with him in the Tardis in the middle of the show.