Is gravitational energy released when a body contracts? Kelvin stated that gravitational energy released due to contraction was responsible for the energy radiated in the stars. Although the theory was wrong, was the assumption practically right? If it's right, how does contraction take place?
It is correct. Contracting stars heat up due to their own contraction. This justifies the initial temperature raise in a star, before fusion begins in earnest.

Kelvin was not 100% wrong, it's just that fusion, over the life time of the star, makes much, much more energy than contraction. The collapse heats up the star at the very beginning, then fusion takes over and makes essentially all the heat you observe.

This is also true of gas giant planets. Even a tiny amount of contraction may raise their temperature measurably. E.g., Jupiter radiates more energy than it receives from the Sun - this is due to contraction, at a rate of 2 cm / year (diameter).

TLDR: Gravitational energy becomes heat.