Various foolish explanations are on offer: the adaptationist hypothesis, the byproduct hypothesis, and the sexual selection hypothesis.
From Bill Dembski and Jonathan Wells at Evolution News & Views:
Leaving aside whether mathematical ability really is a form of sexual display (most mathematicians would be surprised to learn as much), there is a fundamental problem with these hypotheses. To be sure, they presuppose that the traits in question evolved, which in itself is problematic. The main problem, however, is that none of them provides a detailed, testable model for assessing its validity. If spectacular mathematical ability is adaptive, as the adaptationist hypothesis claims, how do we determine that? What precise evolutionary steps would be needed to achieve that ability? If it is a byproduct of other abilities, as the byproduct hypothesis claims, of which abilities exactly is it a byproduct and how do these other abilities facilitate it? If it is a form of sexual display, as the sexual selection hypothesis claims, how exactly did the ability become a criterion for mate selection?More.
O’Leary for News: My cats might be better hunters if they could do math and engineering. But come back in a million years and cats just like them will still be crouching in the long grass listening for rodents.
Meanwhile, some brilliant young nerd is fooling around with transcendental numbers, unable to make a living or find a girl.
Only a society wholly committed to naturalism would find much use in the kind of theories naturalism offers to explain these phenomena: The explanation need not account for the facts. It need only be naturalist.
See also: What great physicists have said about immateriality and consciousness