Slingshot effect is kind of a misnomer, the proper term is gravity assist. As for the matter itself, to keep it simple, in the flyby the spacecraft changes direction and that redirects the velocities. Energy is conserved because what happens is that the spacecraft robs some of the momentum of the planet in this interaction, but obviously the planet doesn't even notice the fact due to the (dis)proportions in mass.
If you want a more in depth explaination you have to consider what happens to the velocities in the heliocentric system of reference: what happens is that the velocity of the spacecraft in the heliocentric SoR can be divided into the planet speed, which is constant, plus the excess velocity, which by definition is the speed at which the spacecraft exits the Sphere of Influence of the planet (implied: in a hyperbolic orbit), and conversely it's the ingress velocity once you subtract the planet velocity. In the flyby the gravity of the planet will provide the acceleration necessary to curve the trajectory, so in the end the initial excess velocity will have rotated of a certain amount, and compounding with the planet's velocity it will give the new exit velocity. I'm shit at explaining stuff, so look at this picture (p.435 of the Curtis)