logical reason is the cooling system and AC condenser is unable to dissipate heat while stand still and being in a traffic jam where combined temp is quite high due to many cars present and ECU shuts down AC to prevent heat up or engine damage. it starts working again whenheat dissipation improves due to car movement.
detailed reasons cud me multiple:
clogged radiator
clogged condeser
bent fan wings
dying fan motors
rusted clogged cooling system
rusted wings on water pump
faulty compressor/ high head pressue causing load overall
engine low compression
leak in headgasket
etc etc.