how to create expire flagged node after custom time
You need the rules module along with its Rules Scheduler module. The flags module is well integrated with rules and you can do a lot of stuff with this combination.

A simplified instruction how to achieve your desired functionality:


Enable rules, rules scheduler.
In admin/config/workflow/rules/components crete an actions component which, when triggered by the scheduler, will unflag your node. You will have to set its inbound variable to 'content' (usage: parameter). Action will be unflagging your node.
In admin/config/workflow/rules create a rule which will start the scheduler (the triggering event should be 'node has been flagged' and the action should be 'schedule component evaluation' which passes the node id (content) to your component.


This way whenever a certain node is flagged with a certain flag, a new scheduler entry is added and when its expired, your node gets unflagged. Bear in mind the entry is only evaluated on cron run, so you will be hitting that cron button many times during debugging.

You can find rules tutorials all over the place, but not so much scheduler tutorials.
This comment is a good starter.