How do horseshoe orbits work?
The horseshoe orbit shape does occur only in the reference frame of the Earth’s orbit. It is a manifestation of a third body problem, and the orbit is in an accelerated reference frame. The loop, which is this distended horseshoe shape, has no central gravitational source inside the loop. As a result the orbit is a “pseudo-orbit.”
From the perspective of an inertial frame in heliocentric coordinates this asteroid is in a circular orbit (topologically a circle) around the sun. When the orbit is closer to the sun than the Earth’s orbit the asteroid has a smaller orbital period, or equivalently it has a larger velocity. It will eventually catch up with the Earth, but it is not necessarily gravitationally drawn into the Earth. It interacts with the Earth’s gravity field in its frame with an effective and repulsive potential $L^2/2mr$, $L$ = angular momentum $r$ = distance from Earth. The gravitational potential plus this effective potential pushes the asteroid into a higher orbital radius. The Lagrange points $L_4$ and $L_5$ act then as attractor points in the rotational frame of the asteroid. Its orbital velocity is now smaller and recedes away from the Earth. Eventually the Earth approaches the asteroid and the process is repeated.
This is a “hunter-chaser” type of orbit. The thinner the horseshoe is the smaller the angular momentum L is with respect to the Earth at close approach. This means the gravitational attraction can become larger. This is a physical way of thinking about this. Technically this problem requires using Hill’s method for the 3 body problem.