Like khun โปรโตซัว said, it has something to do with protein.
"Many lobsters, crabs, and shrimp have a variety of different colors present in their shells. The pink or red color is the pigment astaxanthin, but its molecules are wrapped up in dark protein chains. So the shells are dark. Whenever you cook a protein, though, it uncoils, or denatures, and in the case of these shellfish, that frees the red pigment and the shell changes color. "
PS: Do you know that not every shrimp turns red when they're cooked?