We all know, Solids have defenite size and obviously have defenite volume. Liquid has defenite volume but no shape. Gases have neither shape nor volume. Gas will occupy the available volume of the container. Molecules make use of the available free space for their movement.
Thus in gases, you can externally change the degree of freedom of its molecules. When you increase the container volume, you are increasing the degree of freedom of the gas molecules. And conversely also it is true.
Coming to the question, when you decrease the degree of freedom of molecules (by decreasing the container volume), due to the limitation in their mobility, the excess residual energy has to be given out (All system trend to minimize its energy state). Naturally the gas becomes hot in a big to exchange the excess energy to the surrounding.
(Most of the natural energy exchange is done by heat energy).