The answer to this question lies in the breaking of specific chemical bonds by heat.
When a prawn, lobster or crab is alive and well, scurrying around in its normal habitat, their shell is a dull grey or green colour, which helps them blend in with their surroundings.
But when these creatures are exposed to heat — say, during the cooking process — all the pigments in their shell break down, apart from the one responsible for providing a red colour called astaxanthin. This pigment is stable in heat and is usually bound to proteins in the shell. But as these proteins denature and unwind, it becomes free.
Astaxanthin also gives salmon, krill, plankton and some algae species their reddish colour. It is produced synthetically for commercial use in animal and fish foods (in tiny quantities) to impart colour on those that eat it. Some research suggests that astaxanthin may also have health benefits, and it can be used as a food supplement.