In the series the "Forest of Decay" grows above the petrified remains of ancient trees. Dialogue from the anime and manga suggest that the toxins from the immense pollution humanity caused in the past are absorbed by the plants while water and sand are filtered through the remains of the petrified wood and become purified, which is why the wells that people made have clean soil and water.
The petrified trees seems to be in part inspired by the natural process of petrified wood, a special type of fossilization.
the result of a tree or tree-like plants having completely transitioned to stone by the process of permineralization. All the organic materials have been replaced with minerals (mostly a silicate, such as quartz), while retaining the original structure of the stem tissue
The actual process of petrification and filtering were or touched upon in the anime or manga. However in the manga it's inferred to be part of the artificially process ancient the humans created to clean up the miasma over time.