I personally would never use this particular idiom when giving condolences; it would not be appropriate to talk about death when the feelings are still raw - when someone is still in mourning. This idiom would more likely be used when no emotional feelings are associated to the death, or perhaps when someone is trying to avoid emotional feelings.
In my brief search on the web, no one has been able to prove its origin with absolute certainty. However, I found two theories that were compelling enough to share.
1. One theory is that its origin stems from an old-school suicide technique. A man would tie a noose around his neck, securing the other end to a tree branch or an overhead beam while he propped himself up on a bucket. When he wanted to say goodbye to the world, he would kick the bucket out from beneath himself.
2. Another theory derives from the old method of slaughtering a pig. It used to involve hanging the pig upside down from a beam in the barn - called a "bucket" - especially designed for the purpose. In its death throes, the dying animal would then, naturally, "kick the bucket."
Bucket List
Understanding what "kick the bucket" means results in one to understand the meaning of "bucket list". A list of activities someone wants to do before they die is often called a bucket list, because it is a list of things a person wants to do before they "kick the bucket."
https://en.wiktionary.org/wiki/kick_the_bucket
I would also like to thank my colleagues for today's discussion about death.