There is more to a microcontroller than just the CPU “core”. The die is packed with peripherals. Two of those peripherals are a timer, and an “output compare” peripheral.
The PWM programs those two peripherals, so the timer “ticks” at a given rate (counts up an internal counter), and the output compare watches that counter and either turns its associated output on or off depending on that counter value.
Once the CPU core has configured those peripherals they just run by themselves.
It’s a bit like driving a car. Once you have turned the ignition and the engine is running you don’t need to keep turning the ignition to keep the engine running - it just runs by itself until told to stop (or it runs out of petrol).