In most insects, the brain is located in the head. As is true for any electrical signal, the shorter the distance the signal must travel, the faster it will be received. The location of the brain in the head minimizes the distance between the brain and sensory organs (eyes and antennae) and allows faster communication of information from the environment.
In larval insects just prior to the molt, the brain, muscles and epidermal cells of the head are withdrawn into the thorax and the new larger head capsule is formed inside the thorax. (It would not fit inside the smaller head capsule of the previous stage!) In many caterpillars, an empty head capsule can be seen on the front of the insect.
The head not only contains the brain but the muscles that control the antennae and mouthparts. Tiny insects are cramped for space inside the head capsule and may have smaller brains with fewer neurons than larger insects. A brain can only be so small and still function. An adaptation in many tiny insect larvae is the displacement of the brain into the thorax. The distance between the sense organs and the brain is not too great due to the small size and the insect functions quite well. It is unusual for the brain to be in the thorax of adult insects. Polilova & Beute* describe such an arrangement in Sericoderus lateralis, one of the “minute fungus beetles”. The displacement of the brain allows this species to have a smaller head and still maintain its brain power.
*Alexey A. Polilova & Rolf G. Beute. 2010. Developmental stages of the hooded beetle Sericoderus lateralis (Coleoptera: Corylophidae) with comments on the phylogenetic position and effects of miniaturization. Arthropod Structure & Development 39 (2010) 52–69.