1670s, "system of strict discipline," from the name of French military officer Jean Martinet (killed at the siege of Duisburg, 1672), lieutenant colonel in the Régiment du Roi, who in 1668 was appointed inspector general of the infantry. "It was his responsibility to introduce and enforce the drill and strict discipline of the French regiment of Guards across the whole infantry" [Olaf van Minwegen, "The Dutch Army and the Military Revolutions 1588-1688," 2006].
The meaning "an officer who is a stickler for discipline and regularity in small details" is first attested 1779 in English, but "No F[rench] use of the word in the sense of a disciplinarian appears" [Century Dictionary]. The surname is a diminutive of Latin Martinus (see Martin). Related: Martinetism.