The earliest framing of why the 42 journeys are recorded comes from the parable cited by Rashi (Bamidbar 33:1) and Bamidbar Rabbah 23:3: a king whose son was ill took him far away to heal him, and upon returning the father recounted every stop along the way — here we slept, here it was cold, here your head hurt — so too God had Moshe enumerate every place Israel had traveled.
The Ramban (Bamidbar 33:1) adds a dimension of divine kindness embedded in the count itself: one should not think Israel was perpetually uprooted with no rest, for across the entire forty years they moved only forty-two journeys, and recording them publicly demonstrates God's mercy even within the decree of wandering.
The Hasidic sources extend this toward the soul's inner journey: the Kedushat Levi (Bamidbar, Masei) teaches that the 42 encampments corresponded to the need to gather and elevate scattered sparks of holiness, with Israel dwelling longer in some places and briefly in others precisely according to how many sparks required rectification at each site.
The Noam Elimelekh (Bamidbar, Masei:1) maps the 42 journeys onto 42 spiritual worlds, each with its own character — some of strict judgment, some of mercy — and explains that the language of "journeying" (מסע) denotes damage done to a world by human sin, while "encamping" (חניה) denotes the tzaddik's work of repair, so the verse's alternating pattern of "they journeyed and they encamped" encodes an entire spiritual itinerary of breaking and mending.
The Sefat Emet (Bamidbar, Masei:2) adds that these journeys were in particular related to the forty-nine gates, and that the Torah records them because departure from a place is itself the spiritual elevation — the journeying away is what gives each station its meaning and its lasting place in Torah, a principle the Sefat Emet applies to every human being who must learn to move through the stations of life for the sake of Heaven rather than for oneself.