As stated, it prevents side load.
You have to remove the correct side bearing first, the spacer will move far enough to drift the bearing out using a long rod or even a screwdriver but you'll get nowhere on the one the other side. The rear is the same.
If you look at the workshop manual there's also a correct order to insert the new bearings, the first is driven until it hits the rim, the second is only driven until it snugs that spacer tube and should be fractionally away from the bottom of the recess in the rim.