There seems to be two possible origins. One comes from the belief that those wanting to hang themselves would stand on a bucket with a noose around their neck. The act of kicking the bucket away completes the hanging. However, this theory does not appear to be the best, and really, who uses a bucket when they need to reach something?
The most plausible origin for this term goes back to the 16th century. Back then, the term bucket referred to a beam used to hang or carry items. The wooden frame used to hang animals up by their feet during slaughter was called a bucket. During the slaughter process animals would sometimes struggle and spasm causing them to kick the bucket.
Now you know where this phrase came from. So when you eventually kick the bucket just be thankful that it will not come in this form. I hope.
Thank you Rachel for suggesting this phrase.