After Hamlet has made his two friends, Marcellus and Horatio, to swear that they will not tell anyone about the ghost that they had seen that night they return together into the castle:
"Never to speak of this that you have seen.
Swear by my sword."
However, Hamlet does not reveal to his friends what the Ghost told him about how his uncle Claudius murdered his father and seduced his mother and compelled her to marry him. He does not reveal to his friends the great commission of the ghost: "Revenge his foul and most unnatural murder."
It is the knowledge of his uncle's treachery and his mother's lust and disloyalty which weighs heavily on Hamlet's mind. He is too shocked to realise that his mother could have done something so mean as to marry the murderer of her husband. The worst part is that he cannot reveal this to anyone else and he has to revenge his father's murder all by himself. It is then that he utters this line : "The time is out of joint."
The Elizabethans believed in the Divine Right of the King, that is, the King was God's own representative on earth. If someone murders the ruling king it is similar to murdering God Himself. The consequences of such a heinous act can be horrifying. This is exactly what Claudius has done, he has murdered the rightful king of Denmark and has usurped the throne.
This is what prompts Hamlet to remark, "the time is out of joint," meaning that the natural course of events in history have been upset and that all is not well in the world. Hamlet implies that there is the danger that something terrible might happen in Denmark.
Scholars believe that Hamlet was written between 1599-1601, near the end of Queen Elizabeth's reign. Queen Elizabeth did not marry and the people at this time wondered who would rule after she dies. The end of the Tudor dynasty was imminent and the line "the time is out of joint" echoes the uncertainty of such an unstable situation
Hamlet is referring to the fact that 'destiny' has been forced off its proper course by Claudius's murder of King Hamlet and history is now not going where it should.
A very influential 16th century philosopher was John Calvin, who said that all your acttions are predetermined, in other words 'everything is written' and everybody's actions follow a pre-ordained path decided by God before you were even born.
Hamlet is saying that Claudius has somehow dislocated that path. The true path of history has been 'hijacked' and needs resetting again.