This is most commonly a symptom of a freehub (or freewheel) ratchet not holding. What is happening is that the pawls in the ratchet mechanism
(concept diagram) aren't engaging properly.
Common causes are rust or corrosion, stiff grease or dried oil gluing them, weak or broken return springs, and chipped pawls or ratchet ring. If you're lucky it'll respond to a flush and re-lube, if not replacement is the only option. The exact method for dis-assembly and service depends on your particular hub. If you're unfamiliar with servicing your hub, read some of the available tutorials on freehub or freewheel service for your model hub, or visit your local shop and hope for the best.
BTW- probably 9 out of 10 times, a flush and lube fixes it, so the odds favor an inexpensive repair.