Shopping trolleys, or carts, are quite expensive. So supermarkets, and other shops that provide carts, prefer their customers to refrain from taking the carts home.
But if you're a shopper who doesn't have a car, or money for a taxi, then you either have to buy few enough groceries that you can tote them home in some bag or backpack or old-lady-trolley you bring with you, or you just take the bleeding cart home.
Only if you're angling for some sort of Kindness to Corporations Award would you then return the cart to the supermarket, of course. So forlorn stray shopping carts can be found by the side of the road in many nations. Supermarkets have to hire cart-collectors, and create hotlines you can call to report abandoned carts and enter the draw for some sort of prize.
Some shopping trolleys have security devices that, one way or another, lock a wheel if you attempt to abscond with the trolley. Now the trolleys cost more and the supermarket still has to hire people to go and unlock and return immobilised carts, but at least the trolley-wranglers won't have to go very far.
I think a more common attack on the wandering-carts problem is carts that require a deposit. They're commonplace in Europe and at airports and are slowly becoming more popular elsewhere, like Australia, where I live.
Each cart has a very solid coin-activated lock...
...with a short chain danging from it. There's a doodad on the end of the chain that's a cross between a key and a seat-belt latch, which clicks into the lock of the next cart in line.
(source: Flickr user Polycart)
To unlock a cart from the next one's chain, you have to insert a coin in the lock. The lock captures the coin when it releases the chain, and the coin is of sufficient value (here in Australia, a one- or two-dollar coin) that you'll probably want it back. Unless you've got some pretty heavy-duty tools handy, the only way to recover your coin is by plugging the key thingy on the end of another cart's chain into the lock of your cart.
You can, of course, use any metal object the size and shape of the appropriate coin to operate one of these locks. The supermarkets themselves often sell metal discs with a key-ring attachment that make sure you can always get a trolley, even if you haven't got any change. But the coin-lock system seems to work quite well, overall. It greatly reduces the number of completely escaped trolleys, and also reduces the number of trolleys abandoned in the rain out in the supermarket parking lot.
Except one time, I did.
First there was one cart sitting in the undergrowth by the side of the road, intact, with a coin (or a washer) in its lock. Then, as the days passed, there was another. And another. Connected together, just as they would be back at Aldi.
This taught me a bit of shopping-trolley game theory. If you're taking a coin-lock supermarket trolley home, you indeed do lose your coin (or washer), that first time. But subsequent trolleys taken to the same place can be connected to the first one, and those ones will give you back your money.
All the supermarket can do to stop this is count their trolleys frequently and send out a patrol whenever even a few of them have gone astray, and thereby lose one of the reasons why they opted for the more expensive, lockable trolleys in the first place.
And they clearly can't stop these dudes at all.