How to reproduce: go to biters' hatchery, place factory fast, and get in. The biters start to attack this your factory, just wait and sit in. If biters destroy your factory, you are still there. You can collect everything inside and get out with all this loot. Also, you can wait before biters go away. I think it's bug.
The proposed scenario: get you out instantly if your factory was destroyed. All items inside should be deleted (I mean you can't wait, collect something and get out with loot)