Killing a character and killing the protagonist are two very different things.
The death of somebody close to a character is obviously life-changing and can set them on a new course. It is the death of Bruce Wayne's parents that motivates him to become Batman. Or the murder of Luke Skywalker's parents that induces him to follow Obi Wan and become a Jedi hero.
The death of a protagonist, on the other hand, is much different. Readers typically identify with the protagonist, so the death of the protagonist is seldom enjoyed by them. But it might be if the setup is that the protagonist is choosing death as the only way to accomplish something they care about more than their own life; saving their family, for example. Or saving the world or universe. Or even saving a single person they love.
If the reader is identifying with the protagonist, it can still be a happy ending if they feel like the protagonist died a heroic and honorable death to achieve their goal, if the protagonist died to uphold a high moral principle. Or they feel like the protagonist, by choosing death to achieve an objective, redeemed themselves for their past sins.
Otherwise, if the reader will not feel the protagonist died with honor and courage, you are writing a tragedy. If that is your goal (it has never been mine) then the death of the protagonist is either literal or Karmic punishment for a mortal sin, because they chose to do something (or many somethings) that harms an innocent, or many innocents. They are not dying heroes, but dying as villains. The story is a warning of what awaits the selfish, those who choose cowardice or comfort or self-reward over the welfare of the innocent and helpless. It is difficult to write a protagonist reader's care about and identify with that fits this bill, but these kinds of "good guy caught up in a slippery slope descent into evil" stories can be written.
It will not be considered a "good read" if you just randomly kill the protagonist, killing the protagonist takes a long time for the reader to feel like their own death (since they identify with the protagonist) was morally justified and the "right ending" of both the protagonist and the story.