This joke is based in myth. Ghosts are dead, non-physical beings and as such they can not be killed. Many versions hold that the only 'true' way to permanently deal with a ghost is to resolve their unfinished business. Once this happens, they fade away.
So the implied story is: 1.) I want coffee. 2.) Dies and becomes ghost. 3.) Ghost makes coffee. 4.) Ghost fades away.
The other comments (ie: I don't feel so good) are referencing a character who says those words before they are disintegrated. Hope that helps!