Yeah, it's been many years, but my impression was that things could be explained as an invasive and engineered all-in-one species that terraforms (arrakiforms?) the environment, partly as a way to eliminate competition.

One phase photosynthesizes, one phase sequesters excess water, and one phase... Stirs the lithosphere and eliminates large animals or trespassers?

In the last Herbert Dune book, Chapterhouse, Arrakis is destroyed to eliminate the source of spice, but at least one worm is transported to another planet to begin to turn that into desert, thus ensuring a continued supply.