Douglas A. Anderson has this note in
The Annotated Hobbit:
I'd say
1) The usage in
The Hobbit is similar to that in the imprecation "Confusion to our enemies!", attributed to people ranging from George Washington to Robert Oppenheimer;
2)
Tolkien was using it it in the "schoolboy slang" sense noted above, with which his children would no doubt have been familiar; which leads to
3) It's not "Tolkien", strictly speaking, or even his Narrator, who is using the word, but
Bilbo, in the first case, then
Dori, and finally, all the
Dwarves (apparently in chorus 😄).
I'm sure his children found all this highly amusing.