It is the only way he sees to safe his life.
It is strongly implied that the mystical 216-digit number that Max was researching has a devastating effect on whatever comes into contact with it.
- Max's computer crashes pretty violently at the two occasions when it computes the number.
- When Max tries to write down the number after his computer crashes the second time, he passes out. His abilities to foresee the stock market numbers after that imply that the contact with the number has transformed his brain in some way.
- Sol's death might have been caused by the number. The notes that Max finds in Sol's apartment after his death imply that the conversation with Max has inspired Sol to resume his previously abandoned research of the number. It is reasonable for Max to believe Sol might have discovered the number and the effect of the discovery caused the stroke that killed him.
Max's dilemma now is that by the end of the movie, he realizes that he does not want the knowledge about the number. He knows that people will not stop pressing him into revealing the secret of the number, but he also has reason to believe that the number is too dangerous to share its secrets with anyone, let alone the shady characters that he met during the movie. But how do you forget something that you have learned? How do you un-know something?
The only way he sees is to remove the part of his brain that contains the knowledge of the number. This also robs him of his mathematical skills as collateral damage, but the smile on his face in the final scene, where he cannot solve the math problem that his young neighbor asks him, suggests that he gladly accepts that as the price to get rid of the knowledge of the number.
Is Max aware that drilling into his skull might kill him? Probably. But at this point he is desperate, and might prefer death to the life that he sees for himself if he keeps the knowledge of the number.
Does the number really have those effects or is it all in Max's head? We don't know. The movie is told through Max's eyes, so large parts of the narration cannot be trusted. It could very well be that the events of the film were just a chain of coincidences, and Max's obsession with patterns led him to believe that they were connected by the magical number (which is exactly what Sol suggests in their discussions). Maybe he was even mentally insane. In this interpretation, drilling into his brain removed the part that caused his obsession/insanity. The movie is deliberately ambiguous in this regard, so both interpretations seem valid.