If Hamlet had survived the last act, the story wouldn't truly be a tragedy, would it? Having a noble character with a personality weakness fall from a position of power and influence and ultimately die seems to be the "formula" for a tragedy, right? Plus, the story line of Hamlet was not original with Shakespeare but rather a reinterpreted work. The tale was already known and in circulation, so Shakespeare's rendition was "a remake." (Therefore, he couldn't really monkey around with the original plot, could he?)
Note that there was indeed one change in the concept of the tragedy over time. In early Greek drama (see Aristotle's Poetics), the hero is simply cursed by fate; later on, his downfall is more related to a personality weakness instead.
Some critics see Shakespeare's early tragedies as amateurish in their flagrant and exaggerated dose of "blood and guts." It was all "Hollywoodian," with a bombastic grande finale in which everybody was killed off (in a very graphic way) on stage at the end. Such is the case of Hamlet, too, although most of the deaths are due to poisoning rather than by the sword.
Hamlet seems to be a pivotal point in Shakespeare's writing, for his later works show more reserve, "posh," and power of suggestion.
I do not think that Shakespeare had to let Hamlet die. However, if he was going to write the play as a tragedy, he had to have something at least as bad as death happen to Hamlet.
Tragedies, by their very definition, do not end well. What would Romeo and Juliet have been like if Romeo had come to the tomb and found Juliet awake and they had eloped? It would be more pleasant, but it's not supposed to be pleasant -- it's supposed to be tragic.
The "best" ending I can think of to a tragedy is in Oedipus Rex. He doesn't die. But he does find out he's killed his father and been married to his mother and besides, he puts his own eyes out and is exiled from his home.
Tragedies have to be tragic. If Hamlet hadn't died, something else bad would have had to have happened.
I am left with wondering what other choice was there. The manner in which the play develops, it seems like death was almost inevitable. The play, itself, is a drama where so much about the nature and futility of mortality is revealed. The ability to surmise, the machinations of personal affairs and political power, the questioning of existence, and the futility of good intentions all seem to converge on the play's development. In the final analysis, it seems that death being visited on the primary characters makes perfect sense in Shakespeare's attempt to evoke the highest notions of tragic conditions played out in different individuals and settings.
Yes, I think he had no other option. To begin, as others have mentioned, the play would not have technically been a tragedy without the death of Hamlet. More importantly, however, we must consider what Hamlet's life would have been like had he survived.
His father, mother, and lover were dead. Hamlet killed Polonius, Laertes, and Claudius, and his mother was accidentally killed in the process. His own friends betrayed him, with the exception of Horatio. Fortinbras would likely have remained a shadow in the sidelines, waiting to take over.
To add to that list, Hamlet had many unanswered questions about life, love, and death. He had met and spoken with his father's ghost.
Imagine the repercussions all of those events would have on a twenty-something man. Considering Hamlet's fragile emotions, he probably would have ended up killing himself anyway. Looking through "To be or not to be," there is such a fine line between survival and letting go of life. I do believe that Hamlet would have either ended his life or gone mad: possibly both.
Besides those two reasons, a writer had every right to decide who should or should not die in anything he/she writes. Sir Arthur Conon Doyle killed off his Sherlock Holmes character, but the public outcry was so tremendous that he had to create a plot in which the beloved detective secretly survived! While this gave us many more wonderful Holmes stories, it should have been Sir Arthur Conon Doyle's choice, not the public. A character becomes so close to its writer that, often, it becomes akin to reality. When that happens, it is as if the character is writing the story.
At some point when writing any story, you will find that you no longer have control over what you are creating. Characters you planned to live may die, while characters you thought should die might live. It is a fascinating psychological event, and to take that away from a writer is to spoil, in many ways, the pure intent of the story.