This is a very specific--and very important--section of a larger scene, and to really appreciate what these lines accomplish, a student must consider the lines in context.
At this point in the play, we know that King Hamlet has recently died and his brother, Claudius, has ascended the throne and married Queen Gertrude, his brother's wife and Prince Hamlet's mother. We hardly know Prince Hamlet at all yet except that Claudius and Gertrude are bothered by the fact that Hamlet is still visibly mourning his father, as evidenced by Hamlet's black clothes and his "dark" mood.
Claudius has just spoken to Hamlet, at length, about how it is "a fault to heaven" and a "fault against the dead" to continue mourning like this. He tells Hamlet it is "impious stubbornness" and "unmanly grief" that is making him behave this way. Claudius wants Hamlet to start acting "normally" and to accept things the way they are now. He reminds Hamlet of two things:
- Hamlet is next in the line to the throne.
- Claudius loves him like a son.
Both probably only make Hamlet more disgusted than he already is, but Hamlet doesn't say a word in acknowledgment. His mother asks him to stay at Elsinore and not return to school. He responds to this by saying, "I shall in all my best obey you, madam." He is clearly undermining Claudius by addressing only his mother, but Claudius ignores the insult by saying, "it is a loving and a fair reply." When Claudius says, "Be as ourself in Denmark," he is telling Hamlet, again, to abandon the gloomy attitude and to revel like the rest of the court. Claudius never acknowledges that his "accord," or agreement, with Hamlet is merely Hamlet avoiding a fight or even a conversation with Claudius.
This entire scene conveys the tension and the forced civility between Hamlet and Claudius. Theirs is a relationship that will become more destructive as the play progresses and Hamlet discovers that Claudius actually murdered Hamlet's father, King Hamlet.