I've always understood his choice to play at being mad--intentionally as he is not mad--as being related to his desire, one might more correctly say need, to find out Claudius's guilt. On the one hand, Hamlet is a Protestant who had been studying at Wittenberg, the University Martin Luther is famously attached to. As such, Hamlet has certain strictures upon him that he wouldn't have otherwise, such as not to look for signs and portents and not to commit revenge murder. From his dilemma, it might be deduced that Hamlet's father was not a Protestant. On the other hand, Hamlet has a filial duty to his father, a fealty duty to his deceased King, and an ancestral duty to his father's ghost. These combined duties require Hamlet to honor the Ghost's wishes.
Hamlet's Protestantism forbids him to honor the Ghost's wishes. Thus his torment and dilemma. The only way Hamlet can bring himself to break the deadlock of ideologies is to have incontrovertible evidence of Claudius's guilt--or at least evidence he can put his trust in. Thus, feigning madness assures Hamlet, he believes, peace from which to keenly and closely observe Claudius without, he believes, drawing suspicion upon himself thus exposing his scrutiny of Claudius and his true intent. He has to closely watch, yet not be closely watched, rather be cast off as ... as though mad.