As you get out of a stopped car, press R1 on PS5 or RB on Xbox before your character shuts the door to take cover behind it.
Location and access

What to do
Try the driver’s door on a four-wheeled car with clear space around it. If it shuts first, get back in and press cover earlier on the next exit. This and the double-tap input for leaving the engine running are separate actions.
Related guides
Game controls and tips · How to find enterable buildings on the GTA 6 map