Gravitational slingshots and energy conservation I was watching YouTube video about gravitational slingshots and conservation of energy was explained as "planet loses its orbital energy around sun while spacecraft gains energy"

*

*In solar system it explained as decreased orbital energy around sun but its supposed that spacecraft approach from front side (their initial velocities are opposite)


*What if it approaches from back side, then due to conservation of momentum shouldn't final velocities of both increase? (same direction for initial velocities)
Actually when you think with reference to sun, both cases are ok, they don't violate anything, so it doesn't depend from what direction you approach planet with respect to its velocity. But what if there is no any solar/other systems and orbits and planet is stationary?
What i was thinking for is, lets consider big mass/planet in space but stationary this time, like really absolute stationary. When spacecraft gets near, due to centrifugal force it changes direction of its initial velocity lets say for matter of simplicity by 180 degrees (u shape turn). But due to conservation of momentum, planet accelerates in opposite direction little amount and thats where i got confused.
Looks like total energy is increased.
I was thinking maybe it can be explained with the fact that nothing is stationary in space and there is no absolute speed as everything depends on which reference frame you are using, so there definitely should be some orbital path for that 'stationary planet' but then it violates my first assumption 'absolute stationary'.
When you starting do this thought experiment in completely stationary and empty space, things gets weird.
 A: Consider a simpler example: an elastic collision of two bodies when there is a significant difference in masses.
By going into CoM reference frame, one can show that the velocity of a smaller body after the collision will increase by two velocities of a bigger body $v_2=v_1+2u$. What will happen if the larger body were flying away? It's as simple as letting $u\to -u$. The speed of a smaller body will decrease by two velocities of a bigger body.
In other words, instead of an accelerating slingshot effect, the spacecraft will experience decelerating slingshot effect. (And since the spacecraft lost it's kinetic energy, this energy was spent to increase the angular momentum of the planet, which counterintuitively resulted in an average slowing of the planet. However, it's another story)
A: It is convenient to view gravitational interactions as scattering. To illustrate how this works we take a look at the rest frame of the big planet and look only at the planet/spacecraft interaction for now. This gives the following picture

In this idealised scenario with only the planet and the spacecraft present we see that the spacecraft follows a hyperbola. This means at large distances the path asymptotically becomes a straight line with constant velocity (momentum). The difference between the initial momentum (right pointing blue arrow) and the final momentum (left pointing blue arrow) is the momentum kick $\Delta p$ that the spacecraft got from this flyby. Similarly the planet got a kick equal to $-\Delta p$ pointing in the other direction. But, as you mentioned, this will have neglible effect on the motion of the planet. If you think in terms of these asymptotic momenta and ignore the time interval where the planet and spaceship are interacting this problem is very similar to a hard sphere collision. The time interval where they are interacting is quite long so this comparison should be taken with a grain of salt.
Now by viewing this problem this way a lot of things should be more clear. In case there are no other planets this problem is the same as a hard sphere collision. So if you want to know why energy is conserved you could easily find a proof of that (for example in Vasily Mitch's answer). If you add back the sun you can reason in terms of this $\Delta p$ to find out if the energy will increase. Take the velocity vector of the spacecraft with respect to the sun. Is $\Delta p$ in the same direction as the velocity vector? The energy will increase and you will get a bigger orbit. Is $\Delta p$ in the opposite direction? The energy will decrease and you will get a smaller orbit.
