Sometimes, player characters die in Dungeons & Dragons - it's up to the DM and players to make sure that the death respects the tone of the game and advances the story forward. Death is one of the most variable parts of Dungeons & Dragons. After all, the popular tabletop game is set in worlds where a variety of resurrection spells exist, limited only by the power and willingness of a nearby cleric. After all, true resurrection can bring a creature back as long as their soul is free and willing and they haven't been dead for more than 200 years. The game even has variable rules regarding death, giving players the option of playing a game where they have multiple chances to stave off death, or where a single unlucky dice roll can kill a character where they stand.
In my home Dungeons & Dragons game, we've had two players lose their first character over the last two months. Each death provided a way of not only reinforcing the tone of the game, but also push the story in unanticipated directions. Due to the circumstances surrounding each death, the deaths were also treated a bit differently - although both players had an opportunity to "send off" their characters in different ways and hopefully gain some closure.
The first death was caused by a bit of a fluke - the party was exploring a maze in the feywild and encountered a group of redcaps. The party's warlock (who, due to roleplaying, was hesitant to use his powers) got cornered by two of the bloodthirsty lawn gnome-like creatures and ended up getting wiped out by a series of unlucky hits. To give the death a bit more gravitas than "randomly murdered by evil lawn gnomes," I (the DM) reached out to the player and offered him a choice between dying right there and then or "picking the mystery box" and crafting a better end for his character. He chose the latter option, and we collaboratively crafted an ending for the character where he got partially ceremorphisized by mind flayers and then possessed by his warlock patron to half the transformation - thus turning his character into an evil NPC for use later in the campaign. While some of the other players assumed that the warlock was unwell, the player had the opportunity to give his character in-game closure by spending all of his money on lavish banquets for the party and sending letters to many of his compatriots before the session where his character officially "transitioned" into an evil NPC.
In this case, the dice decided the character's fate, but it ultimately was the player (and the DM) who crafted the character's ultimate end. Giving the player the agency to decide how their character ends their story, or at least allowing them to have input, offset what could have been a senseless character death during a random encounter. It also provided the player to impact the campaign in a more meaningful way and coincidentally gave the DM a new toy to use later on.
The second death was a more "traditional" Dungeons & Dragons death. During a pivotal fight against a main antagonist, the rogue unfortunately was ripped apart by the villain's minions. The circumstances surrounding the death was a collapse in strategy - the players were supposed to retrieve a pivotal item from the villain in order to end his control over his mind controlled minions. Due to a combination of an unlucky grapple and several missed attacks, only one player could actually engage with the villain to try to get the item out of its hands (well, technically tentacles) and so the villain was able to use its minions to directly attack the party.
Because the rogue's death happened during the course of a plot-centric battle, I (as the DM) opted to have the character die on the battlefield. From a story perspective, the character's death right then and there made sense. It provided a lasting reminder as to what the villain was capable of, and it had a touch of tragedy due to the rogue's final actions prior to combat, as she spoke to the then not mind controlled minions and learned that retrieving the item would free them from the enemy's control.
However, this didn't mean that the rogue's story ended on the battlefield. The player picked out funeral arrangements for the character (a viking funeral with the pyre lit by a dragon) and also saw firsthand how her death impacted the party members. Additionally, the character's death also had a major impact on two major NPCs - setting up what could be an interesting plotline moving forward that wouldn't have happened had her character lived. In this case, the player had less control over the character's ultimate fate, but she still saw how her character's death made a lasting impact on the other characters and the overall story. And since Halloween is this weekend, the rogue might make one final appearance before heading off towards her final rest.
Death in Dungeons & Dragons can be a powerful narrative tool, both for the DM and the characters. Should death approach your campaign, look at how it can be used to advance the story (as opposed to a way to shock your players) and collaborate with your players on what they'd like their character's lasting legacy to be.