Acceleration on approach and slowing on departure

A spacecraft accelerates as it falls toward a planet, reaches a greater speed near closest approach and slows while receding. In an ideal unpowered encounter with other perturbations neglected, incoming and outgoing asymptotic planet-relative speeds match, but their directions differ.

This compares far-field speeds rather than claiming constant speed throughout the encounter. Gravitational acceleration remains present; a freely falling vehicle can feel weightless while its trajectory bends.

References: [1] [2]

Why another frame shows an energy change

The planet also moves around the Sun. Adding its heliocentric velocity to each planet-relative spacecraft vector can produce heliocentric speeds of different magnitudes, because the encounter rotates the relative vector.

When the spacecraft gains heliocentric orbital energy, the planet loses a minute corresponding amount. The spacecraft’s much smaller mass permits a substantial change for it and a tiny reaction on the planet, consistent with conservation.

References: [1] [3]

Assists can increase or reduce energy

Encounter geometry can raise or lower orbital energy; merely approaching a planet does not guarantee an outward boost. NASA illustrates outward assists with Voyager and an energy-reducing encounter with Galileo passing Io during Jupiter arrival.

A mission must arrange encounter time, direction and distance and control trajectory errors. Assists can reduce propulsion requirements without replacing every launch, correction or insertion maneuver, and choosing a flyby changes the route and schedule.

References: [1] [3]