"Kick the bucket" is an idiom which means "die".
For example: After Bob kicked the bucket his children all fought over his money.
Kick the bucket can also be used when someone kicks an actual bucket.
For example: Tom accidentally kicked the bucket and hurt his toe.
In the joke, at first it seems like the boy is using this phrase in this idiomatic sense. The girl thinks he is going to tell a touching story about the last thing his grandfather said before he died.
However, it turns out the boy meant "kick the bucket" in the literal sense. He says the thing his grandfather said before he kicked an actual bucket, not before he died.