Meaning and early instances of the idiom
Christine Ammer, The American Heritage Dictionary of Idioms (1997) has this entry for "crazy like a fox":
crazy like a fox Seemingly foolish but actually very shrewd and cunning [Example omitted.] This usage gained currency when humorist S.J. Perelman used it as the title of a book (1944). {Early 1900s}
The Library of Congress's Chronicling America database of U.S. newspapers has multiple instances of "crazy like a fox" or "crazy as a fox" in the modern idiomatic sense, starting with two from 1907. From "Parker Says He Is Insane," in the Spokane [Washington] Press (January 18, 1907):
One often hears the remark, "Kid Parker is crazy." The kid this morning pleaded guilty to being crazy but "crazy like a fox." The kid has some ideas that one seldom finds in the average prize fighter.
And from "Knockerino Points Out a Few Flaws," in the [New York] Sun (June 9, 1907):
What? That's what you have every morning whether you've been out the night before or not? Behave that cutting up! Didn't I see you at 2 o'clock this morning licking up the beads of the hiss fluids like as if somebody'd tipped you off that they were going to stop making it and you wanted to get yours down all at once before the shutdown? I'm as crazy as a fox, hey?
Mad foxes?
But the earliest Google Books match for "crazy as a fox" is much older and seems to lack the ironic sense of the modern idiom. From "How a Western Iago Worked upon the Jealous Feelings of Dolly," in the Detroit [Michigan] Free Press, via The Shamrock (April 8, 1876):
Sneaked here in hopes I'd go, did you?' remarked his wife.
'Woman, are you mad?' asked the man.
'If she hain't done gone crazy as a fox, den I never seed a 'possum!' put in the barber.
A very similar version of this story appears in the Wilmington [North Carolina] Journal of March 31, 1876, again citing the Detroit Free Press as the source.
And an article called "Mad March Foxes," in the Pickens [South Carolina] Sentinel (April 7, 1892) suggests that rabid foxes were known for their "crazy" behavior at least as far back as the 1890s:
CHARLESTON, S. C., March 28.—The mad fox excitement of several months ago is still before the public mind. Numerous articles were published from time to time of the prevailing mania among the foxes in the forests around Pinopolis, Ten-Mile Hill and other neighboring regions of this great country where they raise cabbages. The details of several attacks made by these mad pests were published at the time in The News and Courier.
It will be remembered that one old negro was interviewed who came to town with his clothing torn, claiming that he had been attacked by a pack of foxes that attempted to swallow him. [The man] said that they all appeared to be "crazy een de head," but that he had valiantly dispersed the company with the help of an axe. ...
Another old African was found who said he was riding his mule along the road when suddenly he was set upon by several foxes, who made him dismount, and then they rode off on his mule, leaving him to "foot it." ...
Quite a number of gentlemen of undoubted veracity were seen who said that there was no doubt of the existence of mania of some sort among the foxes. ...
An expert gave it as his opinion that the madness was caused by the long and continued droughts. Statistics were looked up and it was found that in other places the foxes usually died withing two weeks after becoming mad. Some time after the first reported breaking out of the mania no more mad foxes were seem, and the theory advanced was that they had all died.
Last week, however, the news of a horrible death from hydrophobia leaked out. It appears that the boy was bitten a few days previously by a mad fox.
The modern "crazy like a fox" seems not to be very closely linked to the phenomenon of "mad foxes." Nor does it mean simply "crazy" as, for example, "crazy as a loon" and "crazy as a coot" do. Instead, the essence of "crazy like a fox" is that the behavior seems irrational but is actually done in furtherance of some ulterior motive that the observer may not be aware of.
'Crazy as a fox' fox behavior
With regard to what vulpine behavior "crazy as a fox" might refer to, one tactic for which foxes are renowned while being hunted involves circling back to their own earlier trail and running backward in it for a while to throw their pursuers off the scent or at any rate into confusion. A reporter alludes to this trick in "The Cuban Situation," in the [Brownsville, Texas] Daily Herald (January 11, 1896):
The news cabled last evening that Gomez had passed Alquizar and Guerra Melina in the Havana province was received with relief by the friends of the insurgents, though the direction he had taken beyond that was not known, but it was generally supposed that he was bent upon retreat into the eastern provinces, glad to escape the trap set for him. It is evident now that he was merely making a pretence to mislead his enemy and has meantime counter-marched, like a fox doubling on its own track, and tonight he has nearly his whole effective force in the tobacco district in the southern part of Pinar del Rio ready to visit destruction upon the tobacco cop as it has already been visited upon the sugar crop.