The OED gives says it's a variant of "to go ape", cited from a 1955 edition of American Speech, and both are air force slang.
It appears to have originally been US air force (or marine) slang, from at least 1952, applied to troops at a base going a little bit stir-crazy when they can't leave the barracks. Could it be related to acting like a crazed ape, and could the later go bananas and go batshit [crazy] derive from it?
The Routledge Dictionary of Modern American Slang and Unconventional English by Tom Dalzell (2009) says go apeshit means to "lose control; to go crazy" and says it's US from 1951, but the earliest citation given is from 1961.
Page 13 of the November 1954 edition of the US Flying Magazine (Vol. 55, No. 5) offers a possible source:
All Thule [a US airbase in Greenland] barracks are anchored down by buge blocks of concrete. Even with the help of the concrete blocks, the buildings sometimes lift nervously when a heavy Phase 3 gust hits just right, and some of the troops go “ape-sweat.” Ape sweat is a term which means the same as Glacier Goofy, Rock Happy or Snow Stupid. It simply means aguy has snapped his cap for some reason or other, usually because he got bad news from the girl friend.
Alternatively, I expect it's more likely the editors of the mid-fifties Flying Magazine didn't want to print any swearing from those foul-mouthed troops in their magazine and changed ape-shit to ape-sweat.
Flying Magazine from November 1955 reports from Sondestrom airbase in Greenland:
Slang expressions of cynicism such as “apesweat,” “glacier goofy,” snow stupid,” “rock happy,” are scarcely ever heard at this outpost.
The June 1955 Flying Magazine says:
Sharpshooting Williams and his right bower, Capt. Bob Sands, however, didn't “go apesweat” when the chips were down.
Other than some other likely euhpemistic uses, most of the other apesweat results in Google Books are unrelated, although it's interesting to see WWII Canadian soldiers called the 'brandy' they were given 'ape sweat' ("it was often up to 95 per cent methyl alcohol and potentially lethal").
A summary of a 1952 Leatherneck (Volume 35, Issue 2) by the Marine Corps Institute gives a fleeting glimpse of "gone ape" in the summary, but the snippet is unreadable.
A snippet of The Saturday Evening Post Stories possibly from 1953:
“I been watching you since you got here last month, Charlie,” he said, “and I'm telling you you're gonna go ape if you don't get out of of this sorry dump and go to town once in a while. You'll plumb flip your lid. ...
“Man, you have gone ape,” Williams said. “A motor pool keeps him from getting homesick, he says. ...
“Maybe I've gone a little ape myself sitting around here stacking up rotation points,” Williams said, “but you got to admit sending a hot-rod addict to drive the general is a comical idea.”
These have a similar meaning to the (euphemism?) ape-sweat, troops going a little stir-crazy from being stuck in the barracks for too long.
Some snippets possibly from 1954, mostly in a military context:
Army, Navy, Air Force Journal
- Tokyo and points east, Keyes Beech:
"General, we're sorry but we don't think you know what's going on in Colonel ------'s regiment. This man has gone completely apeshit. He's wasting American lives. If he's still there tomorrow we're going to have to file stories on him." Within an hour Colonel was on his way back to the States, a sick man.
(Volume 91, Issues 27-52):
In view of the above, and before we "go ape"
again, I would like to respectfully suggest that. in the future, “Pentagon planners" be advised to see such movies as "Fort Apache," “She Wore a Yellow Ribbon."
- Why I am so beat, Nolan Miller:
There you stand up on your little sandy island and everything else, as the saying goes, is ape shit. You never feel you're fanning out. All company present have got such one hundred percent terrific brains.
... and the hassock and the wrought-iron coffee tables with their glass tops which, someday when everything goes completely ape, I'm expecting to step throug with a big foot.
Already by 1956
we can see more mainstream uses.