I would probably check the spring loaded mechanism that holds the door closed. It may be broken. The reason it opens when you unlock the doors and stays closed with the doors locked is because BMW's have another mechanism that also locks the gas door when the rest of the doors are locked. So when you unlock the car doors, you also unlock the gas door, and it swings open. This is why you cant open the gas door when you have the car locked. It seems to me that this lock mechanism is the only thing keeping the gas door closed. Thats just my two cents...but I hope it gives you some insight. Good luck!
Its the cats pajamas!