The spacecraft Galileo did not get this lift for free, but took some kinetic energy from the earth, just a trace.
First of all, the gravity-assist phenomenon does not occur as something between the spacecraft and earth alone.
Galileo did not come from infinity and fall away from the earth to infinity.
Both are just parts of the solar system, in orbit around the sun.
The earth can influence the speed and direction of Galileo in a certain way because it is large and in motion around the sun.
If the earth were standing still relative to the sun, then the interaction would be symmetrical, and there would be no gravity assist.
The interaction between the spacecraft and the earth involves a perturbation of both their orbits, with a change of direction and energy. When Galileo flew by earth on December 5, 1992, it increased its speed in orbit by 8,280 miles per hour.
Simultaneously, earth changed its speed in its orbit, slowing down by a speed of 2.3 billionths of an inch per year, a truly small but calculable amount.
As a consequence of this interaction, Galileo’s orbit changed from a two-year elliptical orbit taking it out to the asteroid belt to approximately a six-year orbit reaching out to Jupiter.
Earth’s orbit of the sun stayed roughly circular but shrank by something less than a billionth of an inch.