Wiktionary explains the origin was from the days of flintlock and caplock firearms, “…where the half-cock position of the hammer was both a rudimentary safety and the proper position for priming the pan or inserting a percussion cap. The phrase was originally rendered ‘to go off at half-cock’.” The expression obviously came from the occasion time that the weapon unexpectedly fired when it was at half cock. The expression has evolved into describing someone who takes a premature or ill-advised action.