What are the origin and history of the phrase put a sock in it?
In terms of location, it comes from Britain. From ThePhraseFinder...
The imagery behind the phrase is that putting a sock in whatever was causing the noise would quieten it down. What that thing was isn't known. There are suggestions that this may have been the horn of an early gramophone or, more straightforwardly, the raucous person's mouth. [italics mine]
The author of that page says the earliest instance he could find was in the weekly literary review The Athenaeum, 1919. He points out that the fact that it was defined in the reference suggests the term was relatively new at that time. I found a reference a couple of years earlier in Happy - though Wounded! The book of the 3rd London General Hospital, 1917,...
"Put a sock in it, Fusiliers."
Hereupon a sudden and awful silence. The Night Sister has entered the ward.
I suppose the timing (and that earlier instance) makes it likely the expression arose in the military, as much slang does. So perhaps the thing that needed stuffing with a sock was the bugler's trumpet. (Or the piper's bagpipes - especially if he was practising, when others were trying to sleep!)
While I admit I quite like the etymology as given in FumbleFinger's answer, it is possible, according to World Wide Words, that it is merely folk etymology. The explanation is described as a 'well-meaning but misconceived attempt to explain the origin of an existing saying', albeit widely spread such that it is 'unsurprising people accept it'.
Instead, World Wide Words suggests that the phrase's true origin is World War I and some literary extracts from that time period containing this phrase are given as examples. Two of these examples are from two newspapers - one from the UK dated 8 August 1919 and one from Australia dated 14 June 1919. This therefore suggests that the phrase did not originate from Britain exclusively. To quote World Wide Words:
These two citations strongly suggest an origin among servicemen in the First World War, and explain how the expression got into Civvy Street simultaneously in Britain and Australia in 1919 — it was carried to both by homecoming soldiers.
The wartime etymology is also referenced in a blog post on a word history blog. Mentioned in the post is a source doubting the gramophone story. To quote the post directly:
But, according to B. A. Phythian in A Concise Dictionary of Phrase and Fable (1993):
This seems improbable: in the sort of household that alone could have afforded such a novelty [= the gramophone] it is unlikely that a sock would be used in the drawing-room.
And he explains:
In a barrack-room, however, socks would certainly be lying around at night and one can imagine a heavy snorer being shouted at and told to ‘put a sock in it’ (in his mouth). Some such military origin is far more likely.
Based on this information, I theorise that the phrase put a sock in it came into existence during the First World War and found its way into everyday speech in both the UK and Australia (at least) through the returning soldiers.