You have not considered all the forces here.
The road exerts frictional force due to which horse moves forward along the cart and frictional force is also exerted on the cart .
Now both have the same acceleration because friction is a self adjustable force