@Sharm brings up a good point. You have to also consider the notion of what the character has earned.
Every character's story is an arc, a transformation from who they were at the beginning, through the trials of the middle, and the revelation at the end. Arcs are what we resonate with when we recognize the shape/authenticity of a story. Without a clearly defined arc, the reader/player won't have a foothold.
Circle back to the idea that the character earns their fate: if you plan to kill a character off, they have to earn that. Whether it's karma or hubris, the character's death is
shocking yet inevitable. For example, Darth Vader died a hero, but he
died. The karma of all the evil he had done did was not absolved simply by defeating the emperor. However, his arc (fatally flawed -> fall from grace -> redemption) was completed.
I'd love to give good and bad examples but the best I can think of is Game of Thrones. George RR Martin knows how to kill characters. Then you have less ubiquitous shows like the 100, the Walking Dead, Arrow; they've been on both sides of the spectrum.
There is a caveat here: when done right you can subvert expectations by killing a character before their arc is complete, when their death would leave the biggest void. Usually this is right before the couple get together, or right as they're about to gain some sort of freedom, or they believe that they've done something good. Specifically, I think this means at the point of denouement. Before the characters/reader/player can enjoy the moment, it's ripped from them. (But, again, it has to be earned:
shocking yet inevitable.)