The speech is actually fairly surprising if you parse it line by line. Chunks of the following analysis are cribbed from On The Value Of Hamlet by Stephen Booth, which is also the best essay on the play that I have ever come across.

To be, or not to be,--that is the
question:--


So far so good. two distinct ideas, cleanly deliniated.

Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune
Or to take arms against a sea of troubles,
And by opposing end them?


Already the speech has begun to undercut expectations and to push stock ideas of life and death out of their usual contexts. Living -- "to be" -- is here reduced to mere suffering, a passive activity. This action is also rendered passively ("in the mind to suffer"),  while death (via suicide) is presented as a heroic action, in active language. The distinction of the speech's first line is already beginning to blur, with active life rendered as a kind of inertia and passivity, while the achievement of death, the cessation of all action, is rendered as passionate activity.

In addition, the somewhat garden path construction of "whether 'tis nobler in the mind to suffer / the slings and arrows" adds another layer of difficulty for an audience member attempting to interpret the speech.  Is this phrase contextualizing "to be or not to to be" as a question of which is the more noble only in the mind? No, "in the mind" is actually the first clause of the idea of "to be," and attaches to the idea of suffering slings and arrows, ultimately underscoring the passive nature of existence that the speech presents by further reducing it to mental activity alone.

A mind encountering the portion of the speech bolded just above is likely, then, to have a somewhat contrary response. On the one hand, it fulfills the "A or B" logic that "To be or not to be" delineates - it begins a comparison of two ideas in the order originally outlined. But it does so in ways that subvert the easiness of that distinction and that work to press the two ideas together rather than distinguish between them.

In general, we will see that the speech repeatedly conflates opposites into single ideas.

--To die,--to sleep,-- No more;

These six words actually do a lot of work. One gloss for them is that "to die is to sleep never again," a reinforcement of the original contrast of "to be or not to be." On the other hand, this phrasing also means its own opposite -- that "to die is nothing more than to sleep," a continuation of activity rather than its completion. Once more, the opposite ideas of being and nonexistence are being conflated, and the original logic of the speech is being subverted.

A word on the sleep metaphor: popular literary convention in Shakespeare's era used it both for states of life approaching death as well as for death itself, with the afterlife represented as a kind of dreaming. This particular speech will get a lot of mileage out of the fact that it can therefore be used to represent both living and its opposite simultaneously. (This same metaphor also operates outside of the speech in the play itself: "Good night sweet prince: / and flights of angels sing thee to thy rest!")

and by a sleep to say we end
The heartache, and the thousand natural shocks
That flesh is heir to,

1. "Heir": introduces an idea of continuity from generation to generation despite individual mortality that the speech will get a lot of mileage out of.

2. "Heir": a word that is of particular importance to Hamlet's character, since his thwarted inheritance is one of the primary items that motivates him.

3. "the thousand natural shocks/ That flesh is heir to": introduces a Christian ethos the speech (i.e. human beings, "flesh," are heir to the curse of Adam)...

--'tis a consummation
Devoutly to be wish'd.


3. (cont) ...which is immediatedly recast ironically in "devoutly to be wished," which reconsiders the blasphemous act of suicide in a specifically religious light. Additionally, note the heavy lifting that "consummation" does here, simultaneously accenting ideas not only of conclusion, mortality and Christian perfection, but also of sexual completion -- a final meaning that lightly re-contextualizes "flesh" after the fact and essentially doubles down on the ironic and blasphemous nature of this brief aside.

To die,--to sleep;--

A minor variation on an earlier phrase ("--To die,--to sleep,-- No more") that again contextualizes the subsequent passage in terms both of contrast between and conflation of the ideas of "sleep" and "death" (which will be further accented by "sleep of death" below).

To sleep! perchance to dream:--ay, there's the rub;
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;


4a. "shuffled off this mortal coil": 'cast off the turmoil of this life' -- "not to be"
4b. "shuffled off...coil": an act that rejuvenates a snake -- "to be"

In line with earlier metaphors, the shuffled coil here also represents its own opposite, further reinforcing the earlier presentation of life as a kind of suffering, while also presenting the action that concludes life through an image that itself suggests life's continuity, as with "heir" above.

(A similar image that represents simultaneous continuity and conclusion is available in Claudius's speech to Hamlet in the play's second scene. The King, attempting to pull his nephew back to the land of the living, perversely presents "death of fathers" as a "common theme" of life, essentially urging young Hamlet to get over it. In doing so, he simultaneously emphasizes both generational continuity and individual mortality).

5a. "makes calamity of so long life": 'makes a calamity of such great length'
5b. "makes calamity of so long life": 'turns a long life into a calamity'

This phrase underscores the living-as-suffering idea presented in the speech's opening lines, and though its multiple meanings compliment rather than conflict with each other (both equate life with lengthy suffering), the phrase's elision of simple interpretation nonetheless contributes to an additional degree of confusion. 

Also note that the idea of the afterlife as unknown is touched upon here, but only euphemistically  ("what dreams may come"); the speech will return to this idea later.

For who would bear the whips and scorns of time,
The oppressor's wrong, the proud man's contumely,
The pangs of despis'd love, the law's delay,
The insolence of office, and the spurns
That patient merit of the unworthy takes,
When he himself might his quietus make
With a bare bodkin? who would these fardels bear,
To grunt and sweat under a weary life,

A relatively straightforward expansion of the "life is suffering" theme, but...

But that the dread of something after death,--
The undiscover'd country, from whose bourn
No traveller returns,

...this is problematic. The idea of 'no traveller returning' from the dead has already been touched upon in this speech. It is a truism that "no traveller {has yet} return{ed}" from the afterlife in all contexts except within a play where the hero's father has come back from the dead to spur him to revenge. "The dread of something after death" is especially daring in this context, since it introduces the ideas both of the afterlife and of eternal punishment, ideas that should -- but do not -- call to mind Hamlet's earlier encounter with the ghost of his father.

Additionally, though "bourn" in this instance obviously glosses for "limits" -- a concept that the speech obviously fights against -- that is not its only active meaning. Since the word "whose" denotes a personal possessive, "bourn" also cannot avoid a slight but nonetheless real sense of reference to "birthing," i.e. "whose birth," thereby re-introducing a faint sense of life's continuity into a discussion of its permanent conclusion.

The speech has further paved the way for this meaning, in phrases such as "bare bodkin," "bear the whips and scorns" and "fardels bear," for a subtle emphasis on "bourn." Although "bare" in bodkin here means "naked," and although the latter two examples both mean "endure," Shakespeare's use of these words nonetheless creates a rhetorical context where "from whose bourn / No traveller returns" emerges both as a fresh expression of an implicit theme in the speech and also onto well-paved turf at the same time (Shakespeare, incidentally, loves punning on the word "bear" in many of his plays; when Antigonus exits pursued by a live mammal in The Winter's Tale, it is after the play has been riffing on "bear," "bore," "born," "bare," and so forth for nearly three acts).

This phrase thus participates variously in the larger context of conclusion vs. continuity that the larger speech presents, for instance in the succession, coil-shuffling and death-as-sleep metaphors, at the very moment that it is attempting to clearly deliniate the idea that death is final. I suspect (but have no way to prove) that this is why one generally elicits a note of surprise when one points out the italicized contradiction above -- it is surprising because the micro-level tug in this speech between conclusion and continuity helps to paper over the much larger issue of plot discontinuity.

The rest of the speech behaves as though it has been riffing on a coherent idea throughout; as Booth notes, it also describes the action of hearing the speech itself:

--puzzles the will,
And makes us rather bear those ills we have
Than fly to others that we know not of?
Thus conscience does make cowards of us all;
And thus the native hue of resolution
Is sicklied o'er with the pale cast of thought;
And enterprises of great pith and moment,
With this regard, their currents turn awry,
And lose the name of action.

F. Scott Fitzgerald once said something along the lines of how the mark of a first-rate mind is the ability to hold contradictory ideas simultaneously. I submit that the "to be or not to be speech" in Hamlet, Hamlet itself, and indeed most of Shakespeare's plays are all vehicles for the production of great minds.

This speech starts by out by presenting "to be" and "not to be" as two simple opposites to be evaluated in turn, then launches into a series of examples that complicate and subvert and contradict the idea that they are, in fact, opposites at all, then finally comes out of the whole mess with a single idea as though nothing strange has happened. In truth, however the minds of an audience to the speech have effortlessly reconciled a small cascade of irreconcilable ideas: for instance, that death is both a cessation of life and its continuation. This speech gets away with this largely without notice because Shakespeare's rhetorical skills are so subtle; indeed, the speech does a great deal of complex, obfuscatory work at the same time that it is implicitly suggesting that it is simple and plainspoken.

Indeed, the whole play is actually kind of like that.