A recent article on theatlantic.com says “Throughout the ‘20s, records progressively became louder to take advantage of the proliferation of gramophones that had no volume knob. The phrase “put a sock in it” actually references cramming a sock into the horn of a gramophone to stifle the sound on louder recordings.”
A reader on The Word Detective asked about this phrase, writing that the gramophone origin “just sounds too, well, cute.” The Word Detective responded that “Several word-origin books … assert [the gramophone story] as established truth, which it isn’t…. the first print citation for “put a sock in it” found so far comes from 1919.” In that publication, the term was defined, which suggests it was recently coined. The Phrase Finder agrees.
Word Detective goes further, using the Dictionary of Slang and Unconventional English, which “pegs ‘put a sock in it’ to early 20th century military slang use, and ties it, significantly, to another phrase popular at the time, ‘put a bung in it’ (‘bung’ being a very old English word for ‘stopper’ or ‘cork’ of the type used to seal bottles). Both phrases meant simply ‘stop talking’.”