This is another of the euphemisms in common use about death, but it’s an odd phrase and there is debate about where it comes from.
One theory is that it comes from the use of hanging as a method of execution, where the victim was stood on an upturned bucket until it was kicked out from under them, and they died.