I believe that it was important to Shakespeare to establish that there was no possibility of Claudius's finding out that Hamlet had had a long conversation with the Ghost or even of Claudius's learning that the castle was being visited by a ghost that resembled Hamlet's father, the man he had murdered. However, Shakespeare wanted to use the Ghost at the opening of the play in order to capture the attention of his audience. This meant that several guards would see the Ghost and would have to be sworn to secrecy later on after Hamlet meets with the Ghost himself. This seems the only explanation for making such a long, drawn-out business of swearing Horatio and Marcellus to secrecy. Presumably Hamlet will also swear Bernardo to secrecy.
Shakespeare wanted Hamlet to know all about Claudius's guilt without Claudius being aware that his stepson had this secret knowledge. The audience also knows what Claudius did, how he did it, and that Hamlet knows. This is one of the aspects of the play that makes it so intriguing. Claudius is always wondering what is going on in Hamlet's mind. Hamlet must realize that he has the power to worry Claudius, to torment him, without killing him. Hamlet knows that Claudius is putting on a big act, and that his continuous smiling, which he hates so much, is only a cover-up for his guilt and fear, as is his heavy drinking.