It’s all the moon’s fault. Without the moon, something not already in Earth orbit can only come by parabolically or hyperbolically (some which crash into the Earth). But a deflection by the moon can put it into a stable orbit, at least until the moon kicks it out again. Which it is likely to do, given how many other moons we have besides the main one, accumulated over billions of years of moon collection time.
Planets can capture objects that cross their orbits. This thing, obviously, was orbiting the earth-moon system, but it came within one lunar distance of something, either the earth or the baricenter. The most likely perturbation that released it from orbit around the earth-moon barycenter was probably due to the moon.