How do you barrier voltage is developed?

The integration of the electric field across the depletion region is what develops the barrier voltage.