1)the robot explores your house makes a map
2)you turn the robot off, pick him up, and move him to the other side of the house
3)the robot gets turned on again, and told to localize.
4)the robot takes a few scans with his sonar sensors, and compares the local map (what he just scanned) with the global map (the map he's made with previous exploration)
The spot on the global map that has the most similarities to the currect sonar scans is picked as the "I am here" spot on the map.
As the robot roams around, wheel slippage, encoder errors add up over time creating errors in the robots' "I am here" internal variable.
You can calculate the accumulated error, and make the robot localize when the error passes a threshold.
imagine being at a house that you've never been inside, and you have a blind fold. When you first enter the house, you get a quick peek of the layout.
you walk around feeling with your hands (so you don't bump into anything) until you have no clue where you are at. It's time to localize. Pull the blindfold off for a second and take a look where you are at.
You have a map inside your head that you made the first time you peeked. Over time error accumulated in your estimation of your position, and you had to localize... Compare the map inside your head to a scan of the room.