In the sense of a hangover, this word was known in the US and the UK from the 1840s onwards. 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 this was taken over into English:
In this state of parties there is certainly a good deal to be accounted for by that sort of moral dejection, which, in its more material origin and symptoms ... we used, in University slang, to call katzenjammer — the result of over-excitement by rather equivocal potations in not the best company.
The Guardian (London), 14 Nov. 1849.
The word became more widely popular in the US when Rudolph Dirks used it as the name of the family he featured in his cartoon strip. This began 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 was responsible for extending the meaning of katzenjammer somewhat, to refer to a clamour or uproar, not necessarily one caused by alcoholic excess. However, it also continued in its old sense of a hangover for many decades.