It may be that the rich orange smell of the fruit, which folklore has long rumored to be an insect repellent, scares them off, or it may be that the latex-rich leaves gum up the mouth parts of insects, eventually discouraging others.
You could try leaving the fruit around your house, or experiment with planting it or some of the other fragrant plants that have been reported to keep insects away.
The Osage orange, Madura pomifera, a spiny shrub commonly used as a living fence in the American Southwest, is just one of the plants containing chemicals that may (or may not) help repel some or all insects.
There is a wealth of lore about them, and many anecdotal reports of success, though relatively little hard data. Like the Osage orange, many of these plants are also sources of perfume fragrances.
Depending on climate and space, backyard experimenters could include some of the following candidates: marigolds, chrysanthemums, basil (for mosquitoes), rosemary (for moths), patchouli, vetiver, citronella, peppermint, spearmint, and pennyroyal. The tree spices cinnamon and cloves are also reputed to be moth repellents.