Walking using a shopping cart causes you to flex at your lower back and support some of your torso weight on the cart itself. This has two effects. One, of course is that the spine is partially unloaded (less stress loading on the spine). Less load on the spine reduces compression and shear forces which reduces pain.
The other action that forward flexion produces is opening of the central canal and foramen as well at loading anterior structures and reducing load on posterior structures. If the painful structures are posterior (pars fractures or facets), forward bending reduces stress on them. If there is stenosis (narrowing) of the central canal or foramen, this action will also open the channels that transmit the nerves.