Why do you think everything must have a purpose? Indeed, why do you think anything should have a purpose, other than things constructed by intelligent beings such as beavers, humans and ants?
What you perceive as a purpose is simply the natural interaction of chemicals and the application of physical laws. "Lifeless planets" are a consequence of the same processes that produce life bearing planets, minus the conditions necessary to generate and sustain life.