The factor which will keep your spontaneous nanites from consuming their home-world and ultimately the entire universe is... change. Nanites are no more immune to change than any other aspect of existence.
The first generation of the little critters might have come out of the randomness with a perfectly crafted structure made of just the right elements that had come together into just the right geometry within a perfectly accommodating environment of temperature and gravity.
That blessed first nanite would have a virgin world full of resources to choose from, so it might succeed in spawning a few absolutely identical copies of itself. Those perfect duplicates would also have been born into an unravaged world, so they too might find all the parts necessary to sire flawless children. The perfect duplication might go on for a few generations, but sooner or later, the available parts (atoms) would start to run low. When 31 argon atoms are needed and only 23 are within reach, substitutions will have to be made.
Change will have crept into the system.
From there, the nanite Armageddon is inevitable. Before the little terrors have consumed more than a few cubic yards of planet, significant variations will start appearing in each successive generation. Those difference will lead to a fractioning of the nanite population into factions. This, and the growing scarcity of required elements will eventually lead to wars.
But their wars will be different than our counterparts in our human-scale world. These nanites have only two instincts, to eat and to spawn. The factions lack any common interests or goals with which they might forge peace with the other side. Their competition for survival is absolute with enemy corpses providing the precious rare elements need for each side to reproduce. They will fight until neither side is able to persist
...and if by some miracle one side prevails and is able to survive, the whole process begins again. Change wiggles in through the gaps in available elements. Distinctions grow and factions form, and then once again, to war they go.
Like humans, your nanites will spend most of their time and ability trying to kill each other. Luckily for the planet (and the universe), they will never get organized enough to get on with the destruction for which chaos created them.