A closer look at Gravity assist
A spacecraft passing a moving planet can change its speed and direction relative to the Sun.
In the planet’s frame the main effect is a turn. In the solar frame an exchange of energy and momentum changes the onward orbit.
Voyager 2 used planetary flybys to continue from Jupiter toward Saturn, Uranus, and Neptune without carrying propellant for each entire change.
NASA · Basics of Spaceflight: A Gravity Assist Primer · Gravity assists: trading energy with the planets
Want to learn more about Gravity assist? Gravity assist on Wikipedia.

