The answer clearly written in the word of God, Isaiah 57vs 1;
In this world evil is everywhere, sometimes it's unpredictable, it cannot be denied that that some people always think of evil against other people.
Formerly, the world wasn't as bad as it's now, what's happening now is the worse, the world is full of bad and dangerous people, the Bible tells us that we are living in a time, called the perilous times, the evil is around us.
It should not be said, that a good person doesn't die untimely because no one dies without permission of God, God owns our lives and takes can take it anytime he wants, and cannot disagree, because he owns our life.
The righteous die because they are taken away from the evil that is yet to come, God took the life of a righteous person to save him from the evil that is to come, God only can see this evil, he knows what will happen in the future.
Wether a good person lives shorter or longer, it's important to note that God has a reason to take a life a good person, a reason he knows will happen in the future.