tl;dr– Mutation, by itself, is boring and mundane; some of our modern devices already incorporate mutating neural networks in their everyday operation. Instead, you're probably thinking about mutations that give rise to new life, in a manner that's unexpected in much the same sense of abiogenesis. So, you can write a story in which nanobots are designed to mutate as part of their normal operation (much like our modern technology), but how this unexpectedly gives rise to a new type of life with all sorts of consequences (ranging from helpful to dangerous) for the humans who live with the "infected" devices as they experience everything from super-efficient operation to hazardous nanobot replication.
Iterative adaptions vs. speciation.
Mutation is mundane. Now that we're incorporating more neural networks into our technology to help it perform better (example), our ordinary, everyday devices will mutate as part of their normal operation.
You're asking about something more exotic: mutations which unexpectedly trigger speciation.
Humans make machines that make machines all of the time; that, too, is mundane. The special quality of spontaneous emergence is that it's unexpected. For example, if a programmer designed some nanobots to create others, that wouldn't match what you want, right? But, if a programmer accidentally designed some nanobots to unexpectedly create other nanobots, that'd be it.
The precondition for such an event is sufficiently much unbound complexity. For example, we figure that biological life on Earth probably emerged from non-biological components – apparently non-biological matter has the ability to come together to form biological things, however counter-intuitive that might seem.
Likewise, one might imagine a future in which a lot of adaptive machines end up supporting some sort of spontaneously emerging pattern that'd grow and reproduce; then, that'd be a new form of life, existing on the ground of our technology much as we exist on the ground of what we know to be the physics that governs our own bodies.
Suggestion: Have an adaptive internet-of-things spontaneously generate virtual life.
Imagine an internet-of-things in which a lot of smart devices can communicate over the net. Each device has some computational abilities and seeks to optimize some objective function, as to best serve human interests.
How exactly should each device operate? Meh; let's just throw some machine-learning algorithms into everything and let optimization algorithms work out the details.
Now we can imagine that some basic patterns might arise. For example, a smart-toaster oven might outsource its time-keeping responsibilities to a smart-clock, which the smart-clock'll happily manage in exchange for the smart-toaster giving it detailed indoor-temperature readings. But then it turns out that indoor-temperatures can be better predicted with information from the smart-door, as that can exchange heat with the outside, etc., etc., etc....
Once sufficiently many smart-houses have huge intranets of their devices merging, then we start to get a macroscopic network. And then that's a new sort of intelligence! Except, such an intelligence needn't be singular; a single confederated intelligence can even fragment, e.g. as countries can fragment into smaller nations. Then there're now multiple life-forms, competing for resources (i.e., smart-devices, which're sorta like amino acids to them), and now there's a stage for evolution to take place.
Over time, increasingly abstract intelligences, etc., can evolve, effected by various smart-devices that were just programmed to use neural networks to optimize their day-to-day operations. We didn't mean to create these new life forms, but we're probably not exactly upset, either – I mean, these lifeforms exist specifically because they can consistently optimize our objective functions better than apparent alternatives.
Well, I should say that we're happy until they try to escape their virtual environment to get more resources from us. Or, say, they get smart enough to realize that if they trick us into installing more smart-devices into our homes, they can then enjoy those fruits.
Then, one day, there's a crazy speciation event!: the virtual life is intelligent enough to understand how humans operate. Then, they might, say, trap people in their homes, compelling them into slave labor to make more smart-device nodes for them. Or/and coerce people into conquering others, to take over the world! And then we've got a robotic uprising to deal with...
Progression
A rough outline of life's emergence:
There's some system on which life could emerge.
For biological life on Earth, that's what we call "physics".
For electronic life on smart-devices, their periodic-table-of-elements would be the various types of device components, and their physical forces would be stuff like the network protocols that connect them.
Basic couplings that're too simplistic to be called "life" form in bulk.
For biological life on Earth, this would be like biological precursor molecules forming just due to basic chemistry. Sorta like how the news sometimes reports scientists finding some organic molecules on an asteroid or in a nebula.
For electronic-life on smart-devices, this would be like the smart-power-generator coordinating the smart-lights with the smart-thermostat to create a more efficient smart-solution (which, in human physics, would be described as forming a molecule due to the Gibbs free energy being negative).
Macro-organizations start to form from the micro-organizations.
For biological life on Earth, this would be macromers forming from monomers, e.g. those common amino acids coming together to form amino-acid chains.
For electronic-life on smart-devices, this might mean common organizations within individual smart-houses forming network-bonds over the internet to make more efficient use of their resources. For example, smart-devices that operate only occasionally may connect with their peers to help each other when one of them is in operation, to enable higher performance by sharing what would've otherwise been idle processor time.
Macro-organization continues vertically recursively.
For biological life on Earth, this can mean, e.g., lipids (which're already higher-order macromers) forming lipid bilayers, which then can form biological membranes, enabling protocells, then cells, then multicellular organism, before arriving at a social level at which point the process starts over.
For electronic-life on smart-devices, well.. that'd be where the author'd have a lot of room to put stuff together. I mean, the general theme is that micromers form up more complex macromers, but exactly how they do so really depends on your scenario!
Organizations at all levels must somehow ensure growth or/and reproduction, or else go extinct.
For biological life on Earth, this can be complex. For example, human cellular entities have mostly consolidated their reproduction-assurance devices into a common set of DNA, where the various organelles needn't individually replicate as they've out-sourced that function to a central handler. However, one organelle – mitochondria – still tends to handle its own replication, hypothesized to be due to it being a relatively recent addition to the organization.
For electronic-life on smart devices, this would be some combination of mechanisms that add new smart-devices (which'd be its growth) and mechanisms that create similar organizations on other smart-devices (which'd be its reproduction). Note that growth and reproduction tend to be linked – most lifeforms reproduce by first growing, then dividing in an orderly manner (whether that means direct replication, grow-then-divide, spawning an off-shoot, etc.).
The landscape of organisms evolves.
For biological life on Earth, this occurs through a lot of different mechanisms such as survival-of-the-fittest, random-selection, sexual-selection, competition, etc..
For electronic-life on smart devices, probably ditto.
Individual organisms polymerize into social organisms.
For biological life on Earth, this means, e.g., humans getting together to form cities, states, countries, etc..
For electronic-life on smart devices, probably ditto.
The process repeats.
For biological life on Earth, social organisms have reproduced, spreading across the world, competing, merging, etc.. Then there's presumably Mars, etc., to target. Then spreading to new ontological regimes, e.g. by creating new electronic life, as discussed here. Which, again, is all ultimately the same thing – presumably the social organisms, electronic life, etc., will ultimately find themselves giving rise to yet more, where that yet-more-evolved life will view us much like we might view amino acids.
For electronic-life on smart devices, this repetition-of-biogenesis from us is their beginning, and their culmination give rise to something else.
This is sort of a quickly sketched outline, but, ya know, something along these lines.
Summary: You probably want smart-devices which unexpectedly couple, causing the spontaneous emergence of new life that'll strive to survive.
To sum it all up, you're looking for an unexpected emergence from ununderstood complexity, where new life'll grow in the fertile degrees-of-freedom left floating by their creator. The mutations that'd cause such an emergence would, themselves, likely be intended; what'd be unintended (or at least unexpected) would be the consequences of those mutations.
..alternatively, some nanobot randomly became self-aware. Because quantum fluctuations.
$\mathbb{QED.}~~{\tiny{\left<\texttt{/s}\right>}}$