And, aha; wrack means the same thing: “to subject to extreme mental or physical suffering; to disturb violently or convulse.” Webster’s Second Collegiate. “Rack one’s brains” is more common w. brains, however.
When I googled “racking my brain” I got 295,000 hits.
When I googled “wracking my brain” there was only 107,000.
Most of these, by the way were people asking which of the two was the correct spelling.
So clearly, more people thought “racking” was the right answer, even though none of them were sure.
My guess, without having looked it up, but because I love looking up the origins of phrases and idioms, is that it might have to do with rake. Many words have changed and evolved over the centuries from how they were once used; sometimes phonetically or linguistically, sometimes in spelling.
My guess is that raking, like combing, for example, was used to imply searching your memory banks as carefully as you would rake the lawn of leaves – or like using a “fine-tooth comb, to use another metaphor.