Why does the sun have a convection layer and a radiation layer? Why is the outer section of the sun convective but the inner section stable and only radiative? They are both made up of the same kind of matter, both heated by the core.
The onset of convection is controlled by temperature gradients (see the famous experiment from Rayleigh &amp; Bénard. When those become too strong, convection sets in.

How strong a temperature gradient gets, depends on the local efficiency of energy transport inside the star. But for the sun (and other lower mass stars), the surface radiates energy away efficiently, dropping the temperature there compared to the rest of the star, making the outer layers convective. Lower temperatures (not gradients) compared to high-mass stars also play a role in controlling the energy transport for lower mass stars. Cool temperatures will allow the formation of $H^{-}$ (negatively charged hydrogen ions) that give high opacities and thus prohibit energy transport.

For high-mass stars it is the enormously fast fusion processes in the core that 'overheat' this region, again letting convection take over.