I recently learnt that some comets like C/1980 E1 (Bowell) interacted with objects like gas giants in the solar system and gained enough energy to exit the solar system. But from Physics, I know that only if the total mechanical energy of a body is positive, can the body exit the solar system. An interaction with a gas giant should merely convert some of the potential energy of the body to kinetic energy and the total energy of the body should remain unchanged. If so, how can such bodies achieve positive mechanical energy to exit the solar system?
The mechanism by which the path, speed and energy of a celestial object or an artificial spacecraft is altered by massive planets and bodies is Swing-by or gravity assist. Any encounter between a comet and a gas-giant like Jupiter is almost an elastic mechanical collision (though no physical contact occurs) and in any mechanical collision, energy exchange between the bodies undergoing collision takes place. In this case, when the comet C/1980 E1 passed closed to Jupiter, Jupiter passed on some of its mechanical energy to the comet, rendering its total mechanical energy positive and hence setting the comet free and no longer bounded to the solar system. It is the total mechanical energy of the Jupiter+C/1980 E1 that was conserved, not just that of the comet. But the small decrease in the mechanical energy of Jupiter would not have a significant impact on the massive planet.