  Magnetars are highly magnetized neutron stars that can produce X-ray and soft
gamma-ray emissions and that have a dipole of $10^{14}$ G to $10^{15}$ G. A
promising mechanism for explaining magnetar formation is magnetic field
amplification by the MRI in fast-rotating protoneutron stars (PNS). This
scenario is supported by recent global models, which showed that small-scale
turbulence can generate a dipole with magnetar-like intensity. However, the
impact of buoyancy and density stratification on the efficiency of the MRI in
generating a dipole is still unknown. We assess the impact of the density and
entropy profiles on the MRI dynamo in a global model of a fast-rotating PNS,
which focuses on its outer stratified region that is stable to convection.
Using the pseudo-spectral code MagIC, we performed 3D Boussinesq and anelastic
MHD simulations in spherical geometry with explicit diffusivities. We performed
a parameter study in which we investigate the effect of different
approximations and of thermal diffusion. We obtain a self-sustained turbulent
MRI-driven dynamo. This confirms most of our previous incompressible results
once rescaled for density. The MRI also generates a nondominant equatorial
dipole, which represents about 4.3% of the averaged magnetic field strength.
Interestingly, in the presence of a density gradient, an axisymmetric magnetic
field at large scales oscillates with time, which can be described as a
mean-field $\alpha\Omega$ dynamo. Buoyancy damps turbulence in the equatorial
plane but it has overall a relatively weak influence with a realistic high
thermal diffusion. Our results support the ability of the MRI to generate
magnetar-like large-scale magnetic fields. They furthermore predict the
presence of an $\alpha\Omega$ dynamo in the protoneutron star, which could be
important to model in-situ magnetic field amplification in core-collapse
supernovae. [abridged]
