If your trigger for calculating a new random target is reaching the destination, your npc will never get a new path if it never reaches its destination.
Rather than pick a random x/y coordinate to path to, what you want is to pick a random VALID x/y to path to. There are a few ways to do this.
You can put your target selection in a loop to repeat for a new target if the destination is not reachable.
Or you can place a helper sprite with the custom movement behavior with push out solids-nearest set, and use that as your target for pathfinding.