Well, you need a volatile (icy) core covered in a rock or metal shell. This is the opposite of what happens normally when a melted body differentiates.
There are bodies that are all ice. So let's start with that, and figure out how to make a hard crunchy shell like a cosmic M&M.
Planets normally grow by accretion anyway. You just need to move it from the region where it accumulated ice particles and into a region where it accumulates rock or other heavy material. These regions are normally separated in the protoplanetary disk, on either side of the frost line.
So, at first glance, it seems we just need to have a body that grows large as it tacks inward and eventually crosses the frost line. Planets do in fact move around as they influence each other and interact with the surrounding media.
The main issue is that accumulating material causes the body to heat up, both from the energy gained by consolidating the particles and from radioactive materials incorporated. Many asteroids show signs of separating out denser material, and Ceres and Vesta were warm enough to relax into spheres. This is exactly what we don't want to happen.
But... giant supernucules comets do exist; they grew to large size without boiling themselves off. So take that as a given.
So how about this: A "rubble pile" recently got blown apart from an impact, forming a cloud of debris that will mostly pull itself back together again. It formed well inside the frost line but was pushed outward. Meanwhile, out frozen chewy center is moving inward and they happen to cross orbits right when the rubble pile was existing as an extended cloud spread out around an arc of its orbit. The large mass of the center easily pulls it back together again, but the debris gathers around the solid frozen center.
Now these rubble piles normally get blown apart and re-aggregate and indeed stay as loose rubble, not melting from the heat of formation. Again, they exist, it happens. The pieces are mostly in the same orbit already and come back together reasonably gently, compared to random collisions of protoplanets.
Meanwhile, the ice serves as a heat sink: a crashing mountain will blow off a small part of the ice, rather than heating up the whole globe. It stays cold, though loses some mass.
Once it is covered in a protective shell of rock, it can continue migrating inward and collect additional material. The now thicker crust does melt were it is impacted by random arrivals (not part of the same co-moving debris), and starts to form a solid shell. We just have to add to it gradually enough that it doesn't melt through, and cools between collisions.
So, we can quite plausibly get our cosmic M&M!
Now, how do we get it to heat up?
Move it to the oven! It's tacking inward... towards the forming star. It seems most convenient to continue on this tack rather than introduce more bodies.
This region will naturally make rocky bodies, as ice melts and vaporizes, but rock does not. So, the crust will not melt into magma but the ices will melt and boil off.
Now we need to get the temperature just right so the shell becomes soft and plastic, but doesn't melt into magma and sink into the ice. Layering helps: the outer layers exposed to the sunlight will melt but under that is still solid and the solid part cracks and shifts but the melted surface plasters over any gaps that open up as it expands.
Eventually, the initial high-UV phase of the star settles down into normal main sequence, and the oven goes from broil to keep-warm.
You are left with a hollow shell filled with an ocean and a thick atmosphere. Magma from the shell dripped down in places, forming long spires that criss-cross through the interior. The ocean might touch once side of the shell due to density differences, but keeps clearance on the opposite side at the very least.