Planetary fly-by trajectories, or gravity-assist maneuvers, help us boost a spacecraft to higher speeds without expending any extra fuel. This 'free' velocity is provided by the gravitational field of the planet. The trajectory relative to the planet appears as a hyperbolic path, and the fly-by causes the heliocentric speed of the spacecraft to increase if the swing-by is BEHIND the planet, or a decrease in speed if it is on the Sun-side of the planet.
At the distance of the planet, the gravitational potential energy of the Sun is essentially constant during the maneuver, but the heliocentric kinetic energy has increased, so the total heliocentric energy of the spacecraft increases because of the impulse it gets from the gravitational field of the planet. The velocity boost depends on the mass of the planet and how deeply into the gravitational field of the planet the spacecraft penetrates before starting its outbound path. To make this all work, the encounter trajectory has to be a hyperbola.
For more details, have a look at a book such as Orbital Mechanics by John Prussing and Bruce Conway; 1993 Oxford University Press, pages 129 - 133.
Return toAsk the Astronomer