>there actually is no objective answer as to which body gained and which lost energy! Energy is always conserved, but which way the transfer happened depends on your reference frame!
this isn't too difficult to demonstrate: pick an inertial reference frame A such that the spacecraft is at rest following the "collision" (aka the slingshot). In this frame, the spacecraft has 0 kinetic energy post-slingshot; therefore, it lost energy in the slingshot, which was transferred to the Sun. Likewise, pick a frame B such that the Sun is at rest after the slingshot (this would be the more usual frame to pick). In this case, it's the Sun that lost energy, and the spacecraft that gained it.
(depending on one's mechanics background this might appear anything from obvious to very weird and unintuitive)
"Who gained and lost [energy] and how?"
>there actually is no objective answer as to which body gained and which lost energy! Energy is always conserved, but which way the transfer happened depends on your reference frame!
this isn't too difficult to demonstrate: pick an inertial reference frame A such that the spacecraft is at rest following the "collision" (aka the slingshot). In this frame, the spacecraft has 0 kinetic energy post-slingshot; therefore, it lost energy in the slingshot, which was transferred to the Sun. Likewise, pick a frame B such that the Sun is at rest after the slingshot (this would be the more usual frame to pick). In this case, it's the Sun that lost energy, and the spacecraft that gained it.
(depending on one's mechanics background this might appear anything from obvious to very weird and unintuitive)