Some scholars claim that the phrase originated in 17th-century slang, where a "dead horse" was work that was paid for in advance, e.g.
In his book Old England and New Zealand published in London in 1879 the author Alfred Simmons gives detailed explanation and background of the "Flogging the Dead Horse" ceremony performed on board ship by a ship's crew at the end of the first month of their voyage (page 113).