"foolish person," 1953, OED suggests from earlier cant slang nigmenog "a very silly fellow" (1700). Compare Australian and dialectal ning-nong "fool" (1832). The word turns up in various apparently unrelated contexts in late 19c.-early 20c. Wright's "Dictionary of Obsolete and Provincial Words" (1886) has nig-nog as a verb for "to fuck." It also was the name of a fictitious patent medicine that "cures all nervous ailments," etc. in a humor story by Edgar Wallace originally published in 1923. As a term of abuse for a black person (by 1959), a shortened and reduplicated form of nigger.
British slang word with varied senses, not all of them certainly connected; see Partridge, who lists two noun uses: "female pudenda" (c. 1845), which might be back-slang from fan, shortening of fanny (in the British sense); and "nothing," in prostitutes' slang from c. 1940; a verbal use, a euphemism for fuck (v.) in oaths, imprecations, expletives (as in naff off), 1959, "making it slightly less obvious than eff" [Partridge]; and an adjective naff "vulgar, common, despicable," which is said to have been used in 1960s British gay slang for "unlovely" and thence adopted into the jargons of the theater and the armed forces.
"worthless person" (especially a young hoodlum or petty criminal), 1917, probably from punk kid "criminal's apprentice," U.S. underworld slang attested by 1904 (with overtones of "catamite"). Ultimately from punk (adj.) "inferior, bad" (q.v.), or else from punk "prostitute, harlot, strumpet," attested by 1590s, of unknown origin. Related: Punkling. For the possible sense shift from "harlot" to "homosexual," compare the possibility in gay.
By 1923 used generally for "young boy, inexperienced person" (originally in show business, as in punk day, circus slang from 1930, "day when children are admitted free"). The verb meaning "to back out of" is by 1920.
The "young criminal" sense no doubt is the inspiration in punk rock — loud, fast, aggressive, and outrageous — which is attested by 1971 (in a Dave Marsh article in Creem, referring to Rudi "Question Mark" Martinez); widely popularized in 1976.
If you looked different, people tried to intimidate you all the time. It was the same kind of crap you had to put up with as a hippie, when people started growing long hair. Only now it was the guys with the long hair yelling at you. You think they would have learned something. I had this extreme parrot red hair and I got hassled so much I carried a sign that said "FUCK YOU ASSHOLE." I got so tired of yelling it, I would just hold up the sign. [Bobby Startup, Philadelphia punk DJ, Philadelphia Weekly, Oct. 10, 2001]