Hamlet feigns insanity because it allows him to do several things that he otherwise would be unable to do: .
With respect to Ophelia, Hamlet would like to express his intense, irrepressible anger towards her without arising suspicion in her or in others that he is in a hostile rational mental state. This would help prevent others in the royal household from speculating that Hamlet was rationally planning hostile actions such as killing Claudius. (The specific nature of this anger will be discussed later). .
With Gertrude, Hamlet would also like to express his anger towards her, as well as possibly kill her or make her go insane, without arising suspicion in others that he possesses a hostile rational mental state. In addition, he would like to confront Gertrude with the premises of Claudius' crime, without her thinking that he actually believes in them, so that she might somehow think about them and realize that Claudius is guilty. Thus, she will no longer love Claudius (thus providing Hamlet with the psychological freedom he needs to kill him) and she will not believe that Hamlet believes that Claudius is guilty. If she believes this, she might purposely or inadvertently pass on this fact to others, leading to Hamlet's demise. Also, however, Hamlet does not want to confront Gertrude with the crime in a rational way, thus forcing her to make a difficult choice between Hamlet and Claudius, with disastrous psychological results for Hamlet if she chooses against him. .
With respect to friends or colleagues, Hamlet would like to express his anger towards them without arising suspicion that he is in a hostile rational mental state. He also wants to be able to punish them or hurt them for supporting or potentially supporting Claudius, while going free on basis of insanity. .
Feigning insanity also allows him to express his anger towards Claudius, while expecting lenient treatment.