The dynamite is discarded unless the dynamite didn't kill the dead player AND Vulture Sam is playing.
From the Bang! consolidated FAQ:
If the Dynamite explodes eliminating a player, does the character Vulture Sam draw the Dynamite along with all other cards of the player eliminated?
No. To complete the effect of the Dynamite you have to discard it after it explodes. So when Vulture Sam gets all the cards of the player killed, the Dynamite is already in the discard pile.
So,
If the Dynamite hasn't exploded, Vulture Sam picks it up as normal (since he takes all cards from the dead player). From the rulebook:
whenever a character is
eliminated from the game,
Sam takes all the cards
that player had in his
hand and in play, and adds them to
his hand.
If the Dynamite did explode (killing the player), Vulture Sam does not pick it up, since it has been discarded.
If Vulture Sam (or similar) isn't playing, then the dynamite is discarded along with all other cards of the dead player. Again, from the rulebook:
When you are
eliminated from the game, show your role card and discard all the cards you
have in hand and in play.