A hangover is the body reacting to being poisoned. Coffee, like any other liquid you might drink, will help with the dehydration. If your drunkenness has caused you to sleep in, and you normally drink coffee every morning, your headache may be worsened or partially caused by caffeine withdrawal, so a cup of coffee will improve that. And if you're feeling queasy, and take cream and sugar in your coffee, it's a way to boost your energy a bit without eating solid food.
But orange juice, tea, pop, or many other drinks would do the same, with the possible exception of the caffeine depending what drink you choose.