If you want your story to be dark - or at best grotesque. It can be an element of drama or an element of horror, that's your choice. You decide upon the mood, and death of a character is an important factor.
One of most important and common reasons to do it is to prove: "Stuff's gotten serious". You tell the reader the characters are not protected by [Warning: TV Tropes link] plot armor. They are mortal and the danger is real. So, if you feel your adventure becomes too light, killing a member of main cast is a sure-fire (if cheap) way to tune darkness up a notch or two.
Sure, "when it's important to the plot" - that sounds simple and cheap, but believe me, it doesn't have to. Imagine the character was very important, a live key to victory that had to be protected and delivered to the goal point. It all seemed like a straightforward, run-off-the-mill escort/travel story where dangers pop up along the way and the protagonists overcome them one after another. Then suddenly their savior/chosen/hope dies, in a way that shows the enemy is really competent. Suddenly all the secondary crew is left with saving up scraps, fighting with their own hopelessness and facing a battle without hope, desperately seeking an alternate solution. Such a turning point will totally shatter the reader's slightly bored area of comfort.
Or opposite, the death may be essential part of the progress. Strugatski's "Roadside Picnic" exploits it in a great way: a character tagging along as a bait/victim/sacrifice. Make it clear early enough or late enough, the impact will be strong.
Do NOT make it meaningless. You may feel like a character has outlived their usefulness and having them tag along with the team will not add anything of value, so you deem the opportunity to kill them while it still counts for something. It will be cheap. Don't. Get rid of them by wounds, by a necessity, by death of faith. Don't just kill them because you don't need them.
In essence, always make the victim live past their death: as a memory, as an idea, their spirit, their heritage. Whether a boon or hindrance, make their death matter until the very end, changing outlook of the survivors.
Also, death is the ultimate redemption. If you really want to give your villain some depth, have them redeem themselves by sacrificing themselves. If they had their doubts all along, this makes for some quite satisfactory ending.
Thoroughly. Sure bringing a character back from dead is a common trick, but not bringing one who didn't die for sure is a bad crime against the reader, giving them false hope. No, make the death very real, possibly quite graphic and leaving no doubts. It's your choice if it's fast and sudden or if it's a slow, prolonged spectacle, a struggle and a fall - but make it count and make it hit.
One more thing: Remember Chekov's Gun can shoot real ammo and kill people dead. Hang one early enough and keep it conveniently in the background, then let it drop and kill your victim when needed. It creates a very strong "oh shit!" moment, when the solution to an unsolvable bind comes not from a deus ex machina but from an impartial background element that was there all the time and just waited for the right set of circumstances.