It is hard to be sure, but depending on when the flies show up, you can make an educated guess.
Flies have a particular amount of time to spend as egg, larva, and pupa before they climb out of the pupa. In the common fruit fly, this takes about eight to perhaps ten or twelve days.
So if you buy a banana and bring it into your warm home and flies appear immediately or in two or three days, more than likely they came out of the banana skin.
If the fruit sits around for ten days or so before flies appear, more than likely it drew flies that came in from outside.
The buyer would not see pupae embedded in the fruit’s skin because they are only 2 to 4 millimeters (about 0.08 to 0.16 inches) long.