They almost always ask for ID. A lot of criminals with warrants out for their arrest are caught at traffic stops.
I found 5-minute idling ordinances from both CA and Sacramento, but nothing about leaving a vehicle idling in a parking lot for a trip under 5 minutes.
AFAIK, the officer didn’t cite the 5 minute rule. If the cop wasn’t sure how long he’d been in the store, what justification did he have for demanding ID?