A heat pump moves heat. It doesn’t make cold.
One loop of refrigerant, two coils and a reversing valve. Flip the valve and the same machine heats your room or cools it, by carrying heat the other way.
Moved, not made.
Refrigerant is squeezed hot by the compressor, then let expand until it is colder than its surroundings. A coil colder than the air absorbs heat as the liquid boils; a coil hotter than the air releases it as the gas condenses. The cold you feel in cooling mode is simply heat being taken away from your room and carried outside.
What the valve really does.
The compressor always pushes hot gas the same way. The reversing valve only decides which coil receives it, so the two coils trade the jobs of condenser and evaporator. Real systems may use a pair of metering devices or a bidirectional one; this model shows a single reversible expansion device, and the room and outdoor thermometers are illustrative.