This is because of the amount of force that is put on your foot and the area over which the force is applied. Since pressure = force/area, the same force on a smaller area means more pressure.
When you are walking on sand, the force being applied by your body is spread out over the entire surface of your foot. Therefore, there is relatively little pressure on any one point (since pressure = force/area).
When you step on a pebble it is an entirely different story. Instead of spreading the pressure over your whole foot, much more of the pressure is applied to the small area that is actually touching the pebble.
So, more pressure applied on a given area of your foot causes more pain.