Like an animal driven from it’s lair he was looking for a temporary refuge, while he sought safer lodging.
Jean Valjean was not just an animal driven from it’s lair - he was prey. Actively being hunted, he was doing everything he could think of to throw his pursuers off of his trail.
The problem was he had no clear destination in mind. In that sens his doubling back looped and spun, as he actively tried to find a safe place to stay and worked to ensure they were not being followed.
Alas, he saw some officers who seemed suspicious and he worried they were on hsi trail. Hiding in the darkness he waited. A few minutes later four of them appeared, arguing about which way their prey had gone. Much to Valjean’s dismay, the moonlight revealed the face of the man leading the operation: It was indeed Javert.
There is no uncertainty left. Valjean knows he is pursued, and he knows his pursuer is Javert. How? Why? What has taken place to close the gap here? We can conjecture all we want, but I assume Hugo will tell us more in the chapters ahead.