I apologize for bumping such an old thread. However, I'm experiencing this same exact problem. I thought they were fruit flies and refer to them as such, but they are probably phorid flies or something similar as mentioned above. I found a dead dubia in one of my emperor scorpion enclosures white maggots in it. Pretty gross. I removed it right away.
I completely cleaned out my dubia enclosure and they have seemed to reappeared now (a few weeks later) stronger than ever. Every time I remove the lid, a few seem to escape and annoy me throughout the day. I feed the dubia fruit once or twice a week and it seems to disappear rather quickly. I believe I have found the source of the problem...water crystals.
I use a gallon bottle to keep the water crystals in and when I pour them into the dubia's water bowl, quite often some crystals miss the bowl or it overflows a little. This led to moist roach excrement. I guess this has been the breeding ground for these flies as there were a lot of egg casings stuck to the bottom of the water bowl.
I am trying to clean up my act and keep the enclosure as dry as possible. I am now giving collards as the exclusive source of moisture until these flies are completely gone. I'll also try and remove any dead roaches asap.