As a protostar collapses it heats up because the gas particles run into each other. The energy the gas particles had from falling under the force of gravity gets converted to heat energy. The gas clump becomes warm enough to radiate energy. The radiation cross the interstellar dust in the surrounding dense core. The dust absorbs all impinging photons and reradiates them at longer wavelengths (infrared). 