The lesson here is that if you're ever approached by anybody claiming to be law enforcement, even or maybe especially if they're armed and carrying a visible badge, before complying with any instructions they may issue, politely request that a marked unit be sent to verify all identities. If the contact is legit they will NOT be offended.
Backup is always a good idea for both parties involved.