Shakespeare leaves the answer as to whether or not the ghost really appeared to Hamlet as ambiguous (not clear or definite). Ambiguity is really what makes the play great as it creates doubt within the audience members as to whether Hamlet is the noble son they want to believe he is.
If the king's ghost is a psychological delusion, each of Hamlet's actions end up truly belonging to him. There is no larger cause for his actions. Instead, they become the actions of a young man deranged after the death of his father. If this is the case, his delusion would be based initially on suspicion and later proven to be fact, as he does find out that his father was actually murdered.
However, more than likely, Shakespeare intended for the ghost to be seen as real. This is why he makes sure the audience knows others can actually see the ghost before Hamlet sees the ghost.
Still, this belief that the ghost is real because others see it can be explained away. Maybe the guards say they see a ghost and the power of suggestion gets Hamlet to believe that it is true. But the fact is that no one but Hamlet has a conversation with it. This is why the answer to this question is an ambiguous one.
We take the play as it is given to us and this includes the ghost. Within the world of the play, the ghost is is a real character. But, real what? The characters, particularly at the beginning, establish that a ghost is as fantastical to them as it is to us. This helps with the ambiguity of it visitation in a play that is full of ambiguities. But, we know the ghost is not just a figment in Hamlet's mind because others see it as well including Horatio.
Apart from the image-and-reality thematic element that the ghost plays, it also contributes to another major thematic element. In this play the distinctly human quality of remembrance plays an important part. If you closely read the parts about the ghost you will see that all the characters that see the ghost call upon their memory to describe how it looks. It is as if the ghost takes its image from what each character remembers about old King Hamlet. On the parapets it is dressed for war. In Gertrude's closet it is dressed more at leisure.
In this context (and others) Hamlet burdens his mother with attributes of the lowly beasts. This is why she does not see the ghost. She has no memory of her dead husband and has nothing with which to see the vision of the ghost.