An exclamation - a euphemistic shortening of God's hooks (the nails on the cross).
As the meaning suggests, this was originally two words - gad's zooks, which was sometimes hyphenated and now almost always spelled as a single word.
Gad was a common term used to avoid speaking the name of God - an example of a minced oath. That taboo, although still influential amongst the devout, is now much weaker and the use of gad has diminished as a consequence. In the 17th century we would have had a choice of such 'gad' words - gadsbobs, gadsbodikins, gadsbud, gadsbudlikins, gadslid, gadsniggers, gadsnigs, gadsnouns, gadsokers, gadsookers, gadsprecious, gadswookers, gadswoons - gad pretty much anything you like. These share a format with many reduplications - many of which also take an existing word and add a secondary made-up word for emphasis.
The only gad... form to have survived is gadzooks. That is still used but it has gone the same way as prithee and odd's bodkins, i.e. stagey allusions to history that are wheeled out for comic effect - Gadzooks Mrs Miggins, bring me more veal pies. Use of gad with its original intent may have almost disappeared but such obvious replacements of words with similar-sounding invented words that have less risk of offending is still with us - feck being a recent example.
Gad began life in the early 17th century, for example:
Robert Armin's A nest of ninnies, 1608 - "And, gad, she will." and Beaumont & Fletcher's The knight of the burning pestle, 1609 - "By gad, if any of them all blow wind in the tail on him, I'll be hanged."
Gadzooks soon spawned a shortened form of its own - zooks. This is first recorded in Thomas Heywood's The late Lancashire witches, 1634 - "Zookes thou art so brave a fellow that I will stick to thee."
See other minced oaths.