Like, all the time.
It should probably be in their contract at this point.
In fact, this is such a common trope that everyone, not just crazy book nerds, is completely aware of it and probably just as tired of all the injustice inflicted on the poor teachers/father figures/etc.
SO WHY DOES IT HAPPEN??
1. It starts the hero on their journey.
Anyone with any life experience will tell you that once you hit a certain point in your life, you have to do things on your own. You can't rely on your parents or guardians to do it for you. You need to make decisions that affect the rest of your future, and it can be scary. But because you're making your own choices, you have the ability to learn and grow from things that may not have affected you when you were younger.
The same is true with the protagonist of a story. In order for them to grow as a person, they need a shove in the direction of independence. Taking what they've learned from their mentor, they need something to force them out on their own and complete the quest they were given. Because they're doing it all by themselves, they have one to fall back on when consequences knock on their door. Friends and companions might certainly play a role in the story, but they won't be the same solid wall of support and advice that the main character may have had.
See, the thing is, if any of us were given the choice, I don't think we'd choose complete independence unless we were in a situation that seemed worse than even the hardest parts of adulting. The same is true with the hero of a story. Chances are, they don't actually want to do a difficult quest that will permanently alter them as a person, even if they like adventures. So ripping the rug out from under their feet is usually the easiest way to go.
2. It's an easy way to manipulate emotions.
Everyone knows that writers love to make people cry.
It's because we feed off your tears I MEAN IT'S BECAUSE WE ARE WONDERFUL PEOPLE WHO REASSURE YOU THAT YOU IN FACT DO HAVE FEELINGS AND ARE NOT A VULCAN POTATO. The mentor usually means a lot to the hero, even if they weren't the best person on the planet, and depending on the story, they were probably the closest thing the hero had to a parent.
This means that when that person is gone, better yet if they die a tragic death, the hero is left to mourn them. When this is done well, there's nothing wrong it. The problem arises when it's so over-used that there's really no emotions associated with it anymore. Everyone knows the mentor is going to die, so there's no impact when it actually happens.
There's got to be other ways to do this, right?
I certainly hope so. What if the mentor went along on the quest? What if they survived? This would change the story, but maybe it would be for the better. Think about how switching up this trope would affect the plot. I bet having an experienced warrior along would be useful. They could always pull a Gandalf and have other things they have to do while your hero goes on their adventure. I mean, if your protagonist is trying to save all that is good in the world, I'm sure it would be handy to have people in two different places.
If you don't want the mentor to go along on the quest, give them a valid reason that doesn't involve their death. Maybe they have a disability, a war wound, arthritis, the list goes on. There's a lot of things that can keep someone in their house. The older they are the easier this gets. Seriously, arthritis in your knees is a perfectly valid excuse to stay home. I can imagine it would make a long quest difficult, never mind fighting, riding a horse, etc. If they fought in a war or experienced anything traumatic, PTSD can dramatically and permanently alter their mental state. Just make sure you do your research.
Are there situations where it's okay to kill them?
Absolutely. In the original Star Wars series, Yoda was REALLY REALLY OLD. Like, REALLY OLD. It was totally okay for him to die after training Luke. It was obviously convenient timing, but still.
Don't kill your mentor character just because you can, there should be a valid reason for it. And that valid reason should not be "the main character needs a reason to leave", because there have GOT to be other ways to pressure the hero into getting the heck out of their little village and off to a quest. If you have a mentor with already obvious health issues, it might be alright to have them die of natural causes.
In reality, this is a difficult trope to handle because on one hand, the mentor dying might be a good thing for your character, but on the other hand, it's so overused that it's just going to be another trope. If there really is no other option then go ahead, but explore other ideas first.
On that note, what if a hero left of their own free will and of the prompting of their mentor, and started off with confidence instead of a completely broken life? It would be an interesting character arc, since instead of starting off a mess, they would realize over time that life isn't as easy as they thought it would be, and they'd have to overcome their dreams being crushed as they go.
So what about you guys? Is there anything about the mentor's death that you think I missed? What ideas do you have for working around this trope? I'd love to hear your thoughts in the comments.
The rest of the series:
You Want to Go Home and Rethink Your Resurrected Character
You Want to Go Home and Rethink Your Strong Female Lead
You Want to Go Home and Rethink Your Universal Language
You Want to Go Home and Rethink Your Superior Race
You Want to Go Home and Rethink Your Chosen One
You Want to Go Home and Rethink Your Redemption Arc