Hamlet’s most famous soliloquy certainly contains lines that indicate his desire for death. While it is possible that Hamlet is just performing in this scene, I do not believe it is likely.
Hamlet truly thinks he is alone. When Hamlet is alone, he lets his guard down and becomes a vulnerable man who does not know whether he should take another man’s life or not. Hamlet agonizes over what to do because he believes murder is morally wrong. Likewise, Hamlet believes suicide is also a sin.
Another reason why I interpret Hamlet’s words as genuine is because this is not the first time in the play where Hamlet discusses suicidal thoughts. In act 1, scene 2, when Hamlet is alone on stage, he expresses a desire for death, “or that the Everlasting had not fixed / His canon 'gainst self-slaughter!” (131-32) This expression shows that Hamlet has thought of suicide, even at the beginning of the play.
In light of these facts, I do not believe Hamlet is feigning madness in this soliloquy but rather expressing genuine emotions and thoughts.