They have magnets in the ground - you'll usually see a strip of slightly different coloured bricks, which have a sea of trolleys all around.
When the locking wheel goes over the magnet in the ground it triggers the brake to lock down and hence lock the wheel. This makes it very awkward to push when one of the four wheels are locked.
When I worked at Safeway as a kid, I had a plastic trolley unlocker key which reset the locks. They don't always work flawlessly, someone in our store hurt themselves when the trolley just decided it wanted to move no further and slammed on the brakes, queue the person going almost over the handles.