Let me see if I understand you correctly...
- You take your fully charged AirPods out of their case
- You "connect" them to your iPhone and put them in your ears
- You are sure they are working correctly by hearing some sort of content through them
- You close the AirPod CASE = empty of AirPods
- The AirPods lose their connection to your iPhone at that moment
Does that describe your issue?
OR
Is chris_g1 correct when he assumes that your AirPods are IN THE CASE when you shut it?