It is often said that this expressive, if less than sensitive term, derives from someone who is being hanged kicking the bucket from underneath them. But there is a lack of firm evidence to support this. In the earliest recorded instance of it in 1785, it is defined simply as "to die".

It is true that John Badcock's slang dictionary of 1823 refers to an unfortunate soul called Bolsover kicking a bucket away to "pry into futurity" (which would in itself be an interesting euphemism!) but a probably more reliable source, the Oxford English Dictionary, points out that a secondary meaning of "bucket" is "beam" or "yoke" and it could well allude to pigs being slaughtered and struggling on it. This usage persists to the present day in Norfolk, Eastern England. It may also relate to the word "Trebuchet" meaning "Balance" and Shakespeare used it in this sense in Henry IV, part one.

Holy water buckets have also been suggested, as has a goat kicking over the bucket holding its own milk, which could point to the death of reputation, rather than actual physical death.

"Kissing the Gunner's Daughter" (used by Ruth Rendell as a book title) refers to a naval flogging; and "Dropping Anchor", also of naval derivation, to getting married.

More Info: en.wikipedia.org