Even with the ignition off, cars still have power in their battery and therefore electricity running through it. That’s how you can use your key clicker to open doors when the ignition is not on.
Most cameras allow this power to be routed to your dashcam so you can record while parked up at night or when you are otherwise away from your vehicle and the engine is off.
Typically, unless you specify otherwise and this is an option, the recording won’t be constant as this could drain the battery. However, via the use of sensors, the camera can detect when another vehicle or person is close, tampering with your car, or a collision has occurred. It will turn on recording to capture important evidence.
Check the model of the cam carefully to see what features it has and how may or not implement recording while the engine is off.