Given a pn-junction as in the picture below. Which quantity determines the width of the space charge region? Or in other words, why don't the electrons in the n-doped region wander towards the positive charge, so that the space charge region widens?
Which quantity determines the width of the space charge region?
The final dimensions of the space charge region (also called depletion region) are due to an equilibrium between diffusion effects and electrostatic force.
When bringing an n-doped semiconductor into contact with a p-type semiconductor, the free carriers from the n-type material (electrons) diffuse into the p-type material. Likewise, the positive charge carriers from the p-type material (holes) diffuse into the n-type material.
This diffusion causes a build-up of negative charge in the p-type material and positive charge in the n-type material, as can be seen in your picture.
This in turn creates an electrostatic potential, making it increasingly harder for both types of charge carriers to diffuse across the junction. Eventually an equilibrium is reached.
why don't the electrons in the n-doped region wander towards the positive charge, so that the space charge region widens?
I'm not entirely sure about this (more satisfying answer at the bottom), but I'll give a possible explanation. It is important to see you have a different situation before and after the depletion layer forms:
When first forming the p-n junction, the p-side is missing electrons (has holes), while the n-side has spare (free) electrons. The charge carriers diffuse to even out this balance.
After the depletion region is formed, even though it is charged, the material itself is in the most energetically favourable state, because the free charge carriers are gone.
The image below clarifies this further: the charge carriers diffuse as to 'fill in the grid'. This filling creates ionized dopant atoms, resulting in a net charge in each side of the depletion zone.
Thus, even though the depletion region is charged, it is not willing to take in charge carriers to neutralise it, because its 'electron grid' is full.
Alternative answer (from the comments)
Actually, the diffusion barrier can just be described by electrostatic forces. Say a depletion zone has formed. Now suppose electrons were to diffuse from the n-type material into the depletion layer. This would electrically neutralise part of the depletion zone, but they would leave behind a positively charged region in the n-doped material. This induces a new electric field that would pull the electrons back, thus preventing the carrier diffusion into the depletion zone.