Hiccups don't serve a useful function anymore, but they were useful to our very ancient ancestors.
Hiccups are a great way to ruin a good meal, a sad movie, or a first date. They're annoying, sometimes painful, and completely useless. That is, they're completely useless to humans.
To early fish and amphibians, the motion of a hiccup was vital to continued survival. Humans' ever-so-great-grandcestors were just beginning to use lungs to crawl out of the water. When roaming the land, they needed to suck air down into their lungs.
When they plunged back into their watery homes, they needed to keep their lungs free of liquid. To accomplish that, they had the ability to close the glottis, the passageway into their lungs. In other words; the hiccups mechanisms began!