
In the sense of a hangover, this word was known in the US from the middle 1840s. It was taken from a well-established German word (it turns up in at least one work by Goethe, for example) which derives from Katzen, cats, plus Jammer, wailing or distress. In German it could also mean the unhappiness or depression that follows intoxication and so developed in American English a more general sense of what one might call a case of the willies.
The word only really caught on when Rudolph Dirks used it as the name of the family he featured in his cartoon strip. This began life in the Sunday supplement of William Randolph Hearst’s New York Journal in 1897. The Katzenjammer Kids featured Mamma Katzenjammer, her twin sons Hans and Fritz, and The Captain (who suffered so much from the mischief of the two boys). The strip was modelled on an earlier one in Germany, Max und Moritz, drawn by Wilhelm Busch, and the family was obviously ethnic German. Since the kids were not drunk but raucous, Rudolph Dirks seems to have caused the meaning of katzenjammer to extend somewhat.