They do whatever they still can.
So, a monster grabs you with its horrible pincer (reducing your speed to zero), and at the same time supernaturally fills you with terror such that the only thing you can think to do is run away. But it still has a hold on you.
The rules-first interpretation of this would imply that you can't pull out of its grip (that is, use your action to escape) because you are too busy whirling your feet in place like Scooby-Doo and going nowhere.
This is absurd. If you try to run away, you will try to pull out of its grip, so your action is to try to escape, and you should get your Athletics or Acrobatics check to do that.
It also leads to the paradox shown in this question: if we treat the grapple as limiting the space you have available to move (which is how a grapple actually works, after all), then Fear's limitation on your action wouldn't even apply, and you'd be free to do any action.
What if you have zero speed because you're chained to a wall? Does that count as having no space to run?
The solution is to recognize that taking the Dash action with zero speed doesn't represent your character doing anything, so it's not an action. It's like taking the Cast a Spell action when you don't know any spells.