I thought of a species that acts on a hive mind. They are about the size of a 5 year old. Whenever they see a threat to their brethren (or king and queen) they explode (not like a fiery explosion). When they explode, they release a gas that can either be toxic or flammable. Are any of these things possible?
Maybe you should take a look at the ant Camponotus saundersi .
It self-destructs to release the toxic substances:
When combat takes a turn for the worse, the worker ant violently contracts its abdominal muscles to rupture its gaster at the intersegmental fold, which also bursts the mandibular glands, thereby spraying a sticky secretion in all directions from the anterior region of its head. The glue, which also has corrosive properties and functions as a chemical irritant, can entangle and immobilize all nearby victims.
Sure. Modern honeybees seem like a proto-example of what you're talking about - stinging protects the colony, but sacrifices the individual. A true hive mind would be more difficult to arrange with known physics - unless we're okay with it being very slow, in which case the individuals composing the hive mind could effect mind-to-mind contact by a very complex system of pheromones. This seems like a natural outgrowth of the modern behaviour of a number of species of ant.
As for the explosion - nothing particularly difficult about that, in principle. For example, if the creature has a sac storing sulfuric acid and a source of fluorite internally, it could combine them to produce a large amount of hydrofluoric acid gas. A great deal of gas forming very rapidly inside a creature without particularly strong structural integrity would cause something like an explosion. Hydrofluoric gas is a toxic gas that is able to pass through skin relatively unhindered; walking through the area where such a creature exploded would not be a pleasant experience.
A similar sort of chemical reaction could produce a flammable gas instead, if you want.