Hamlet feels the duty to revenge his father's death for several reasons. The most important one is that his father's ghost has come to visit him specifically to incite him to do so. The Ghost says:
If thou hast nature in thee, bear it not.
Let not the royal bed of Denmark be
A couch for luxury and damned incest.
This brings up a second reason why Hamlet wants to murder Claudius. Gertrude has been widowed, deceived, and corrupted by Hamlet's villainous uncle. Hamlet believes his mother is committing adultery and incest, and for some time he suspects that she might have even been an accomplice in her husband's murder. Hamlet feels that he, himself, along with his family has been besmirched and dishonored by the hateful Claudius.
Hamlet has a third reason for wanting to assassinate his uncle. Claudius not only stole the crown from Hamlet's father by murdering him, but he stole the crown from Hamlet, who should have been his father's rightful successor. Claudius took advantage of the fact that Hamlet was away at Wittenberg to get himself elected king.
In Act 5, Scene 2 of the play when Hamlet is talking to Horatio, Hamlet enumerates his reasons for needing to assassinate King Claudius:
Does it not, think thee, stand me now upon—
He that hath kill'd my king, and whored my mother;
Popp'd in between the election and my hopes;
Thrown out his angle for my proper life,
And with such cozenage—is't not perfect conscience
To quit him with this arm? And is't not to be damn'd
To let this canker of our nature come
In further evil?
In addition to the reasons Hamlet had from the time he encountered his father's ghost, Hamlet (as he tells Horatio) now has the additional reason that Claudius tried to have him killed by sending him to England with a letter calling for Hamlet's execution. If Hamlet kills the king now, he will be acting in self-defense, because Claudius will surely act publicly or secretly to have his nephew killed, especially when he learns that Hamlet forged a letter which led to the executions of Rosencrantz and Guildenstern when they reached England. Horatio responds to Hamlet's above-quoted question by saying:
It must be shortly known to him from England
What is the issue of the business there.
Once Claudius learns that Hamlet knows he intended to have him beheaded by the English, Claudius will realize that his own life must be in danger. In other words, both men will be acting in self-defense. Claudius knows that Hamlet will try to kill him to keep him from killing Hamlet. And Hamlet knows that Claudius will try to kill him to keep him from killing Claudius! The news from England has not yet arrived with the English ambassadors, so both Hamlet and Claudius can continue playing cat-and-mouse with each other before and during the fencing scene. Claudius is already dead when the English ambassadors arrive.
AMBASSADOR:The sight is dismal;
And our affairs from England come too late.
The ears are senseless that should give us hearing
To tell him his commandment is fulfill'd
That Rosencrantz and Guildenstern are dead.