In general terms, by the end of Hamlet neither the King nor the Queen really think Hamlet is mad (crazy). As noted above, Gertrude does seem to think he's only upset by his father's death and her "o'er hasty" marriage to Claudius. In turn, Claudius criticizes Hamlet for grieving too much and too openly, attributing any odd behavior to this excessive grief.
Before long, though, we discover Claudius's role in the former king's death and we understand he's determined to find the cause of Hamlet's odd behavior simply to discover whether or not Hamlet knows who killed his father. He claims outwardly that Hamlet is mad; inside he's convinced Hamlet knows his secret.
Gertrude really does wonder about her son's sanity when they talk in her bedroom and when Hamlet has inadvertantly killed Polonius. Her son soon convinces her, though, that he's angry and upset but not mad. She leaves their meeting and tells Claudius Hamlet is, indeed, mad; however, she does so to help maintain her son's cover not because she believes it.
In the end, then, they're both quite aware of Hamlet's sanity but continue to act as if the charade were real.