They illustrate that they are nearing a very spiritual place
This question was answered in a Reddit post:
They're called Hokora, and they're small roadside shrines in the Shinto tradition. Here's picture of a real one:
The heavy clustering of them in Ghibli movies tends to be unusual, as they are often solitary or spaced out, rather than awkwardly placed right around each other. This is a subtle way to acknowledge to Japanese audiences that the characters are in a strange place. Witness how Chihiro's expression intensifies when she notices them as her dad passes by in the car.
Since those shrines are supposed to house kami, or spirits, a huge cluster of them indicates an area of high spiritual activity. This is something that is likely lost on western audiences in such a specific way, but yet they still retain a strong feeling of mystery about them, even without knowing their meaning.
—tomrhod, r/Ghibli (Reddit)
The magical world they enter is inhabited by spirits, and the main location, a bathhouse, is dedicated to having the spirit guests relax and set their minds off toil and stress. Whether these houses represent a neglection of spirituality (which would be further supported by the theme reinforced in the question), or whether the spirits are there out of their own volition to "take a break", and so they possibly abandoned those houses/shrines, or whether those shrines were placed there by people aware of the nearby spirituality, or whether they got there by mystical methods, as a consequence of so much spirituality - that's left unclear.
The goal of showing the audience the pile of hokora was to indicate that the family is approaching a strange, mystical place with a lot of spirituality, since we see a giant amount of them, rather than the typical few.