"Nearest wall" would be easy, but it's a weak algorithm would only work with very specific level designs.
It can only work for uniform wall tiles, maybe from a tilemap, and even then it would be illogical for more complex walls. For example, in the following image if blue were the player and red were the enemy, green was the nearest wall, then the pathfinding target would be at yellow, which is silly.
If you want to do it like this anyway:
On "flee" state
Pick nearest wall to enemy - Create helper "target" sprite at wall
While target sprite is overlapping wall - Move target sprite one pixel/tile/step at angle(player.x,player.y,target.x,target.y)
Pathfind to target, destroy target
If enemy does not have line of sight to player, stop pathfinding, change state