Hamlet has just finished talking to the ghost and finding out that his father was murdered by his uncle, Claudius. The ghost has left and Hamlet swears Marcellus and Horatio to an oath not to reveal what they have seen or what Hamlet is trying to do, even if he pretends to be mad:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy. ...
How strange or odd soe'er I bear myself,
As I perchance hereafter shall think meet
To put an antic disposition on,
That you, at such times seeing me, never shall,
... by pronouncing of some doubtful phrase,
As 'Well, well, we know,' ...
Or such ambiguous giving out, to note
That you know aught of me: this not to do,
So grace and mercy at your most need help you, Swear.
At first, the two men see no reason for swearing an oath but both Hamlet and the ghost insist. The ghost requires they swear:
Hamlet then laments that he is alive during this time ("O time is out of joint"). It's the time in which his father was murdered and, being the king's son, he is the culturally required person to "set things right." But he is not happy about it and laments being born at the time--out of joint, out of proper alignment--that requires he avenge his father's murder.
Culturally, revenge killings were the norm, as illustrated by Fortinbras. It is Hamlet's relatively new religious beliefs--beliefs in time out of joint, time out of alignment--that make revenge killing something to lament: Fortinbras accepts revenge killing for his father/King's death as an honor.
"Time is out of joint." In other words, time is dislocated. Time is not in the right place. Time is wrong. Time is broken.
Instead of Hamlet's dad being king and everything being 'straight', Hamlet's uncle has broken the true path of time and history by murdering The King and stealing his crown. Claudius has broken history and Hamlet was born at the time that requires he must fix it, whether he would or not.
"O cursed spite, that ever I was born to set it right"
Time is out of joint because the normal royal succession from father to son has been disrupted by Hamlet's uncle usurping the throne.