Why didn't Prince Hamlet become king after the death of his father? How is it that Claudius became king?
Primogeniture was not practiced in Shakespeare's day. Although King Hamlet had a son, that son's succession to the throne was not automatic. Perhaps the King had not yet named his heir, which would open the kingship to election by the nobles. There is evidence of this in Hamlet's comment following the death of Claudius and his own fatal wounding:
I do prophesy the election lights on Fortinbras.
It is likely that after killing King Hamlet, Claudius used Hamlet's absence at school and the fact of his marriage to Gertrude to manipulate that election so that he could be king. He was certainly a skilled diplomat, and there was definitely an immediate need for rulership, given the impending threat from Norway. It seems very likely that Claudius used this pretext to manoeuvre his way onto the throne.
Throughout the Middle Ages, Denmark utilized what is known as an elective monarchy to crown its next ruler. This form of government contrasts with the common form of hereditary monarchy where the office of king is passed down to the oldest son. In an elective monarchy, the parliament, which consisted of Lords, elects the country's next ruler. While Prince Hamlet was in Germany attending the University of Wittenberg, Claudius usurps power after he murders his brother, King Hamlet. It is plausible that Claudius stepped in to receive the crown after his brother died by using the Queen's influence to win the necessary parliamentary votes needed to become king. In Act IV, Scene 2, Hamlet alludes to how Claudius became king by saying,
He that hath killed my king and whored my mother, Popped in between th' election and my hopes (lines 69-70).
Hamlet laments how Claudius essentially stole the thrown and mentioned that he intervened in the election to become king. One can infer that if Claudius was clever enough to seduce Gertrude and murder King Hamlet, he more than likely used Gertrude to influence the Lords to elect him king of Denmark while Prince Hamlet was out of the country.
Claudius becomes king while Prince Hamlet is away at school. When Hamlet's father dies, his mother, Queen Gertrude, marries Claudius, who is her dead husband's brother. Thus, King Claudius and Queen Gertrude rule Denmark when Hamlet returns after his father's death. Once home, Hamlet is visited by the ghost of his father with the truth that he had been murdered by Claudius. These events, which occur as part of the play's antecedent action, drive the tragedy that follows.