Particle-in-cell simulations of pulsar magnetospheres: Transition between electrosphere and force-free regimes