The oldest formulation of the question appears in Bamidbar Rabbah 23:3, which opens with the parable of a king who brought his sick son to a distant place for healing and, on the return journey, recounted every stop along the way — here we slept, here you had a headache — with the conclusion that God similarly commanded Moshe to enumerate all the places where Israel had provoked Him.
Rashi on Bamidbar 33:1 cites this same parable and draws from it that the encampments were recorded to publicize God's kindness: although He decreed that Israel wander in the wilderness, one should not imagine they were in constant restless motion — the full forty years produced only forty-two journeys, the majority of which fell in the first and final years, leaving the middle decades comparatively settled.
Ramban on Bamidbar 33:1 builds on Rashi's approach and adds a second rationale: the recorded journeys strengthen faith in the great miracles performed in the wilderness, so that future generations who see the list of encampments will know and recognize those wonders — pushing back against the rationalist tendency to explain away the desert miracles as natural phenomena.
Rabbeinu Bahya, Bamidbar 33:1 makes that anti-rationalist concern explicit, arguing that without the Torah's detailed account a person schooled in natural philosophy might convince himself that the signs and wonders performed through Moshe were merely natural occurrences, and it is precisely to uproot that corrupted belief and plant genuine faith in the miracles that the Torah extended itself in narrating the journeys.
Rabbeinu Bahya, Bamidbar 33:2 adds a further dimension: the names of the encampments themselves signal the inner spiritual state of the people at each stage, so that when Israel moved in their thoughts from evil to good the attribute of mercy shielded them — hence encampments named Har Shafer and Matkah — while when they moved from good to evil the attribute of justice was arrayed against them, hence encampments named Charadah, Dofkah, and Marah.