These lines in act 1, scene 2 of Shakespeare's Hamlet are part of a conversation that Hamlet is having with his uncle, Claudius, now King of Denmark after the untimely death of Hamlet's father, and his mother, Gertrude, now married to Claudius.
There is some question as to how long it's been since the death of Hamlet's father. Hamlet first says two months, then he says it's only been one month.
HAMLET. But two months dead: nay, not so much, not two:
... and yet, within a month.... (1.2.141, 148)
Later in the play, Ophelia confuses the matter further.
HAMLET. ... look you, how cheerfully my mother looks, and my father died within's two hours.
OPHELIA. Nay, 'tis twice two months, my lord.
HAMLET. So long?... O heavens! die two months ago, and not forgotten yet? (3.2.119-124)
Nevertheless, it's been at least a month since Hamlet's father died. There are no stage notes from Shakespeare about Hamlet's dress or emotional state in this scene, but it becomes clear from the dialogue that Hamlet's overall demeanor is one of grief and melancholy over his father's death.
CLAUDIUS. How is it that the clouds still hang on you? ...
QUEEN: Good Hamlet... Do not for ever with thy vailed lids
Seek for thy noble father in the dust. (1.2.68, 70-73)
It appears, too, that Hamlet is dressed all in black—"thy nighted color" (1.2.70), "customary suits of solemn black," (1.2. 81)—which would be appropriate for someone in mourning.
In England, up until about the middle of the sixteenth century, the mourning period for a monarch was usually six months to a year. In the latter half of the sixteenth century, however—and with the ascension of Elizabeth I to the throne after the Catholic Queen Mary—the Protestant Reformation had taken hold in England, and private and particularly public mourning was discouraged. Mourning was considered a sign of weakness, impiety, and a lack of belief in a resurrection in God.
Consistent with this Protestant view, Claudius and Gertrude take exception to Hamlet's manner of dress and his demeanor for what they consider is an excessive show of mourning. Of course, part of their motivation for reprimanding Hamlet is that they would prefer that Hamlet not continually draw attention to his father's death and to Gertrude's seemingly hasty—and as Hamlet calls it, "incestuous"—marriage to Claudius (1.2.160), which occurred far too quickly within the mourning period by any standard.
Gertrude calls Hamlet to task for seeming so "particular" (1.2.78), which is to say, for being so noticeable and so excessive in his grief over his father's death.
Hamlet protests that his actual grief far exceeds his ability to show it in either his demeanor or in his choice of clothing.
HAMLET. ... But I have that within which passeth show,
These but the trappings and the suits of woe. (1.2.88-89)
Claudius is growing impatient with Hamlet, but he doesn't want to antagonize Hamlet unnecessarily or upset Gertrude, so he takes a diplomatic tone with Hamlet, while at the same time clearly advocating for the current Protestant doctrine to which he believes Hamlet should adhere.
CLAUDIUS: 'Tis sweet and commendable in your nature, Hamlet,
To give these mourning duties to your father;
But you must know, your father lost a father;
That father lost, lost his, and the survivor bound
In filial obligation for some term
To do obsequious sorrow. But to persever
In obstinate condolement is a course
Of impious stubbornness; 'tis unmanly grief;
It shows a will most incorrect to heaven...
We pray you throw to earth
This unprevailing woe.... (1.2.90-98, 109-110)