Awesome question. There is a very careful balance that a writer must often achieve, especially when dealing with iconic characters but really with any main protagonist. Yes, you absolutely want your plot to have stakes and all too often the stakes meet a necessary limit by the narrative protection of the main character. There are a few problems and choices that a writer faces in determining to shuffle loose the mortal coil of a main character. There are also creative solutions to these problems and I will come to them later. The first is that it shuts the door on continuing that character's story. As a writer the option to continue a character's story is appealing because in developing that character you grow an attachment to them, and honestly, it's convenient if you don't know what to write next to check in and say, "Hey, I wonder how Rick is doing. Let's continue his adventures." The second is you've built the narrative for the reader around these characters. These are the characters with lives and interesting tales to tell. As a reader, imagine if Harry Potter and Hermione Granger died halfway through the first novel and then we had to follow around Quidditch player #2 for the rest of the book. Would you continue reading? Probably not. Would there be a series? Nope. And to piggyback off that, point 3: if a character does become iconic enough, you run the danger of fan attachment becoming unsettling and unnerving. Arthur Conan Doyle introduced Moriarty to kill off Sherlock Holmes because he had become sick of and weighed down by the character. What happened next? He received death threats and nearly lost his publishing deal, and was forced to retcon one of his most famous works and trap himself in the cycle of Holmes. Now obviously not every character you write is going to be Holmes but you have to prepare for that possibility if your story takes off. Even trying to find a replacement often does not fly. Look at when the Bourne movies tried to replace Damon with Renner. That movie tanked and they had to bring Damon back. When Superman died, it was a huge deal, but the replacements were not selling and so they had to bring Superman back.
However, modern writers especially have been doing a lot of interesting stuff to deal with this problem and raise the stakes a bit. The easiest solution is to have several main characters, so that you can afford to lose some. George R.R. Martin and Robert Kirkman get away with what they do because they gave themselves enough characters to play with that they could raise the stakes by killing off some main characters without damaging their ability to continue the story. You still find yourself attached to these characters and so losing someone like say Ned Stark is harsh and painful but you still want to watch. Doctor Who dealt with the problem by introducing Regeneration (though that runs up the opposite problem of now you expect the Doctor to eventually die but also not be dead) in order to kill off their main characters and still have a show. God of War deals with the problem by introducing the next generation of character so now you can kill Kratos and still have games as the son.
Now all of this becomes moot if you are looking to end a series and move on from it. Then, feel free to kill everyone. Or no one. It becomes less important if you know you are not going to continue. But only if you are absolutely sure that you don't want to continue and don't shoot yourself in the foot. For example, Firefly can never return in its truest form because two of the main characters are done. They can do prequel books but that series will face some issues if it tries to move forward without Wash and Book.
To wrap up, the goal of a writer is to continue writing interesting work and selling interesting work. When you have a character you don't want to let them go (or are contractually forbidden from doing so in some cases). If you want to make stories more unsettling and make it possible for main characters to die, you should still provide yourself a safety net or be ready to walk away from that world at the end of it. Hope this helps!