This would be behaving like a caged animal, and in a game, that's good, and better than a smarter algorithm. You don't want them to be idiots, but you don't want them to be magic, either.
The old "follow the left-hand wall" maze-solving strategy is another naive way to get out of a trap. It's not fun gameplay, but it's naive and it exists, so better naive strategies do too.
It also doesn’t at all address inter-unit collisions, which is a big topic in RTS pathfinding.