The context of this quote is Hamlet's growing suicidal ideation and disillusionment with humankind. He has just wondered to himself in a soliloquy ("To be, or not to be") whether he should live or die, but his fear of what might come after death keeps him from the act....
The context of this quote is Hamlet's growing suicidal ideation and disillusionment with humankind. He has just wondered to himself in a soliloquy ("To be, or not to be") whether he should live or die, but his fear of what might come after death keeps him from the act. At this point he is disgusted with himself, saying the "pale cast of thought" keeps him from behaving decisively, whether it be to kill himself or avenge his father's death. Beyond that, as he soon expresses to Ophelia, his faith in people has been utterly shattered. It has shaken him to the core that his uncle may have murdered his father. How rotten, he wonders, can people get? Being a contemplative person, he has also examined his own conscience and found that he too is capable of evil: The idea that the capacity to do wrong is an integral part of being human has struck him forcefully in a way it never had before.
More specifically, the context is as follows: Ophelia walks in on Hamlet at the end of his "To be, or not to be" soliloquy to return to him certain "remembrances" he has given her, a signal she is breaking off or cooling the relationship. He denies ever having given them to her. She insists he did, and more importantly, with kind words of affection, but says the costly gifts have lost their value to her now that he has become "unkind" to her, meaning both cruel and out of sympathy. He tells her he loves her and then that he does not.
At this point he advises her bluntly to enter a convent or nunnery, meaning she should take vows of chastity and never have children, telling her that he seen things in his own heart, such as pride, vengeance and ambition, that make him despair for humankind.
Hamlet is so oppressed by his realization of evil in the world, an evil that seems so pervasive and intractable as to infect everyone and everything, including himself and Ophelia, who he once (and arguably still) loves, that he does not believe the human race should continue, and clearly, at this point, is not about to marry the woman he loved.
There is much more that can be unpacked from this passage, but that is the basic context.