Evidence from seismology, mineral physics, and core dynamics suggests a layer with an overall stable stratification in the Earth's outer core, possibly thermal in origin, extending below the core-mantle boundary (CMB) for several hundred kilometers. Yet vigorous deep mantle convection with locally elevated heat flux implies unstable thermal stratification in some regions below the CMB, consistent with interpretations of non-dipole geomagnetic field behavior that favor upwelling flows in places below the CMB. To resolve this apparent inconsistency, we investigate the structure of convection and magnetic fields in the core using numerical dynamos with laterally heterogeneous