How do insects know what is edible?
Insect feeding behaviour is generally triggered by one or more conditions which may include colour, shape, chemical traces or temperature.
Insects generally locate food based on some combination of olfactory, thermal and visual queues (colour and shape). If their minimum criteria are met to specified tolerance, they will attempt to feed on whatever is nearby using their usual feeding method. 

When these conditions appear on the 'wrong' target, it attracts insects and triggers feeding attempts. Insects can be triggered to feed on atypical food sources if the relevant aspects of their environment match those of their normal feeding environments. For example, here is a report from a professor of entomology recollecting his observations of being bitten by pea aphids while handling plants, which he assumes is because of the scent on his hands.

We can exploit this in various ways for research. One is for artificial blood-feeding of insects: most systems, like the Hemotek membrane feeding system, warm blood to the body temperature of the host. They do not normally resemble a target host in any other way. Some blood-feeding insects have very specific requirements for temperature (for example they will only feed on blood if it is heated to the body temperature of birds; the same blood heated to mammalian body temperature will be ignored) but we do not need to make the target look or smell like the natural host. Other species may need olfactory cues, which can be provided by researchers rubbing the membranes on their forearms before placing them on the feeding system, or by breathing on cages as you add the food.

A second way we exploit this is for insect traps. Although not all traps work this way, some work by mimicking the host and attracting insects that are looking for a meal. This can be via olfactory/chemical mimicry (for example carbon dioxide baited traps - try Googling "CO2-baited traps") or visual. Different degrees of visual 'deception' may be needed; for instance to attract tsetse flies, colour is important but shape is not:


  [tsetse traps] often use electric blue cloth, since this color attracts the
  flies. Early traps mimicked the form of cattle but this seems
  unnecessary


(https://en.wikipedia.org/wiki/Tsetse_fly#Trapping)

The exact reason why blue is so attractive to tsetse is unclear:


  But, why are tsetse flies attracted to blue and black colors? What is
  the evolutionary advantage for them? It has been hypothesized that
  certain areas on humans, where tsetse like to bite, are a darker
  shade. Or, that the dark color simply identifies the object as not
  plants.


(https://www.acsh.org/news/2016/11/28/do-dark-colors-really-attract-tsetse-flies-10471)

If such behaviour increases the fitness of the insects, there is a selective pressure to change the cues used to identify situations where feeding behaviour is appropriate, which may result in consistent feeding shifts. We can infer by comparing insect taxonomy and feeding modes when shifts in diet have occurred. For instance, the moth family Calpinae has evolved piercing mouthparts to feed on fruit, but species in the genus Calyptra ('vampire moths') have adapted to feed on blood (which generally moths cannot access because their mouthparts cannot pierce the skin).