When a neutron or proton enters an atomic nucleus, it behaves like a ball hitting a rough wall: it can bounce off in different ways, depending on where it hits.
The atomic nucleus is like a musical box: inside, nucleons (protons and neutrons) move along their orbits, like pins plucking the comb. But in some nuclei, such as magnesium-32, this box plays a tune you wouldn't expect from the usual shell-filling scheme.