How did Hamlet decide killing himself wasn't the right thing to do?
In his famous "To be, or not to be?" soliloquy from act 3, scene 1, Hamlet begins by discussing all of the reasons why it might be easier to simply take his life, but then he says, "To die, to sleep. / To sleep, perchance to dream—ay, there's the rub" (3.1.65-66). In other words, the problem with death is that we don't really know what comes after it.
For in that sleep of death what dreams may come
When we have shuffled off this mortal coil,
Must give us pause. There's the respect
That makes calamity of so long life. (3.1.67-70)
Hamlet says that the fact that we don't know what will come after death gives us something to worry about. This is the reason we often hang on to life and extend our suffering longer than we might if we knew what the future would hold. He lists many of the things that make life seem hard or unfair or even unbearable at times, suggesting that we only choose this life because it is better to fight the devil we know than the devil we don't, so to speak. We at least understand life's hardships, but death's hardships could be even worse, and that is a risk most of us don't want to take, including Hamlet. Thus, our fear of death makes us avoid it, and so Hamlet chooses not to take his own life.