The reason why a gas heats up when it is compressed into a smaller space, is because the ambient heat that the gas possessed in its original volume, has now been confined to a smaller volume—same amount of heat but now more concentrated—the temperature goes up.