People at this time period did believe in ghosts and that ghosts had actual purposes in attempting to contact the living. In Act I, scene i, the guards are enduring the cold night to watch against any intrusions, which more easily occur when a country has lost a king and may seem vulnerable.
The ghost appears, and it becomes clear to the audience that he wants to speak to Hamlet. He appears ready to fight, as he is dressed in his battle gear. This could mean that he is cautioning them about the impending war or that he has some other battle to fight. He appears in his own form, which makes the guards recognize him. He appears three times, ensuring that the guards pay attention to him and seek to find out what he wants.
Basically, the ghost continually appears until they figure out that it is Hamlet he wants to see in order to get revenge on Claudius for his murder.