This relatively famous speech by Hamlet comes at a point in the story where Hamlet is trying to accept the information about his father and mother and uncle. He knows his father was killed by his uncle and his mother did nothing to stop it. He also knows that through madness shown to the rest of the castle, he will unearth his uncle as the killer and avenge his father's death.
It is a speech about how Hamlet is debating either staying the course to his uncle's eventual death or killing himself before this process is over. It is a speech filled with the last of Hamlet's reasoning before he succumbs to total rage and madness over his father's death and his mother's betrayal. He is also questioning suicide due to the church's staunch belief that to kill yourself is to commit a mortal sin and therefore be condemned to hell.
Hamlet fears both not being able to suffer nobly and then complete his task as well as dying and not becoming immortal. It's the waiting that is truly getting to him.
This speech is most curious indeed, and even more, its placement in the Play. Two sources of Hamlet place the speech at different locations.
As we have learned, Hamlet is a grand philosopher and a somewhat religious person. He likes giving himself or others deep talks on this or that subject, just as how Gandalf might revise some old laws on his fingers.
Observe his talk just seconds before he sees the ghost for the first time; that will give you a hint of how his mind works.
Many unobservant critics have taken one or two lines of Hamlet and run hell loose with them. Once you do that, you miss Hamlet completely.
Read all of Hamlet as if you were dealing with a huge syllogism: lines explain lines, and all the lines together explain Hamlet.
Horrible assumptions to make (should be avoided for common-sense sake)
Hamlet is convinced that the ghost is his father's spirit.
Hamlet trusts the gossip info received from the dubious ghost.
Hamlet wants to kill anybody at all.
Hamlet at any time considers suicide
To be or not to be
This is a philosophical question:
Whether the time before your birth is exactly the same as the time after your death.
The affirmative is true for all living things except intelligent beings.
That is, men, women, girls, boys, fetuses when they die, they survive death in their soul.
Hamlet shows this by his metaphor of Death/Sleep/Dream
Death(Mors) and Sleep(Somnus) are twin brothers in Greek and Roman mythology.
Hamlet observes how Sleep is not the end of one's day. He says dreams come, that is, there is still activity even after sleep.
He goes back to death, and says it is not the end of one's life - what dreams may come...
Hamlet is not being skeptical here, he knows for a fact that the human soul is immortal, that is, it cannot be affected by death, and is indestructible. In fact, it is this truth that helps him rashly challenge the ghost in Act One.
Hamlet knows about the pseudo-philosopher, Brutus, from Shakespeare's Julis Caesar. There, Brutus is unable to follow through with his reasoning: he says at one time that it is cowardice to kill one's self, then runs off to kill himself.
But Hamlet is far more too sensible than both Brutus and Horatio (another pseudo-philosopher) combined. Remember how he stopped silly Horatio from killing himself?
Hamlet is obsessed with life, and rightly so. He recognizes that there are two kinds of life, the one before death, and the one after death. If Hamlet thinks of the environment of the afterlife as a country, he also agrees with himself that there is a Governor there and that there is justice.
Hamlet rolls over in his mind the absolute absurdity of suicide.
To run from this life because of toils and troubles, only to enter a foreign country that has its own rules and regulations - flying to others we know not of.
I think that one mistake the ghost made was to represent itself as a suffering being, bound in chains and fire. I should think this is one reason Hamlet cannot bear to kill (himself, Claudius or anyone). But the fact he records the most kills in the Play tells you that the Ghost accomplished its task by ruining Hamlet.