It looks like the sense of blunder came from French, so we have to look to French etymology. Unfortunately as we often see in English, nautical language is rich, and often unwritten and poorly documented. So we may never get a perfect answer.
One source (and not a great one) I've found says it's uncertain, but speculates:
L'origine est assez douteuse, possiblement à rapprocher du crochet utilisé par les marins pour accrocher quelque chose et dont on a souvent besoin quand on a commis une bévue (objet tombé à la mer, accostage loupé...).
The origin is rather doubtful, possibly close to the hook used by sailors to hook something and which is often needed when one has committed a blunder (dropped something overboard, missed landing...).
Another source speculates:
Le sens figuré du mot gaffe, que nous connaissons tous à travers l’expression faire une gaffe (= maladresse) elle-même attestée depuis le Larousse de 1872, possède la même origine, liée au langage des matelots. La raison possible en est que l’on peut tirer au lieu de pousser (ou inversement) en utilisant mal cet outil au maniement visiblement assez difficile, bref se tromper.
The figurative meaning of the word gaffe, which we all know through the expression of a blunder) itself attested since the Larousse of 1872, has the same origin, linked to the language of the sailors. The possible reason is that one can pull instead of pushing (or vice versa) by misusing this tool visibly difficult enough, in short be mistaken.
The 1872 edition of Larousse (dictionary) is online and searchable. It has:
Dans l'argot des marins, Faire une GAFFE, Faire une sottise
In the langauge of sailors, make a GAFFE, Make a blunder [sotisse these days is often translated as stupidity]
So it definitely comes from a figurative use of the nautical term. The slightly later Dictionnaire étymologique de patois lyonnais, Tisseur 1887 adds nothing but confirmation.
At this point it's worth noting that (as opposed to faire une gaffe) faire gaffe has almost the opposite meaning -- pay attention. Among other figurative uses Avaler sa gaffe (to swallow one's gaff) is to die.
Modern Larousse isn't much help -- it just says the sense of blunder derives from the verb meaning to hook a fish with a gaffe. But this suggests something to me: French uses poisson (fish) figuratively in poisson d'Avril (April fools) to mean being caught out (or having a paper fish stuck to one's back). This origin of this is "uncertain" wiktionary (though there's some speculation about the sign of Pisces which now ends on March 20th but calendars have changed).
(all translations machine-assisted; my French isn't great)