After the steam valve closes the steam expands pushing the piston down the cylinder. Using the steam expansively is the only way to get good efficiency from a steam engine. At the end of the stroke the exhaust valve opens releasing any remaining steam pressure. The pressure in the cylinder is zero until the piston is nearly back to the beginning of the stroke. At this point the exhause valve closes and the air in the cylinder is compressed.
Compression helps make the engine run smoothly.