In short, scientists usually conclude that pain is unlikely to be found in insects in the way it is defined in humans, but this is difficult or impossible to test directly.
In humans, pain is often described as a "subjective experience involving a class of sensations with which is associated a characteristic 'negative affect and aversive drive'". So to simplify, pain is defined as a sensation that causes negative emotions and reduces the behaviors that an individual was performing before or during the stimulus. Note that with this definition, it is hard to differentiate pain from fear or response to an unpleasant but non-painful stimulus.
Eisemann, C. H., Jorgensen, W. K., Merritt, D. J., Rice, M. J., Cribb,
B. W., Webb, P. D., & Zalucki, M. P. (1984). Do insects feel pain?—A
biological view. Experientia, 40(2), 164-167.
To put this more clearly, pain in humans is defined as resulting in a "a protective stimulus-avoidance response".
Fiorito, G. (1986). Is there “pain” in invertebrates?. Behavioural
processes, 12(4), 383-388.
Fiorito (1986) notes "Venom used for incapacitation of prey probably does not inflict
pain, as it may be disavantageous because pain may increase struggling on the part of the prey: it is indeed when venoms are painful that they can function in defense.". This is probably the argument most commonly employed to support the idea that invertebrates don't feel pain: insects can't do much about injuries or intoxications so feeling pain is unlikely to be adaptive because it is unclear how it could elicit a response that would increase their survival.
Many invertebrates are autotomic which means they can voluntarily detach legs or antennae (like a lizard's tail) to avoid being captured by a predator, in this case it is hard to imagine an insect experiencing a pain that would be comparable to the level of pain of a human loosing a leg, because it would incapacitate the insect and reduce its chances of survival. Insects could instead have a direct stimulus to behavior response without any conscious emotions or feelings, comparable to a very simple computer program: "if pressure on this leg; drop the leg".
However, there is at least one case known in ants of wound treatment that would suggest this argument is not valid at least for this species of ants:
Frank, E. T., Wehrhahn, M., & Linsenmair, K. E. (2018). Wound
treatment and selective help in a termite-hunting ant. Proceedings of
the Royal Society B: Biological Sciences, 285(1872), 20172457.