To prevent the cart from getting stuck, make the path wider. It's already difficult to fit through a one-tile-wide passage.
Not bad option would be a "rollback" function. If no one interacts with it, it rolls back a short distance.
However, those who get stuck will still end up in a situation where the cart is stuck, unable to move forward or backward.
The best option is to interact more closely with the cart. Right now, you need to move a couple of meters away from it to make it follow you. Or turn. Ideally, you and the cart become one, like a horse. This will make it easier to turn or make final turns in tight spaces.