Shrimp, before it's cooked, is a very unappetizing gray-blue color. This color, it turns out, is the exoskeleton (you know, the shrimp's external skeleton).
Now, to explain how that exoskeleton turns pink we have to get scientific on you. Here we go: the exoskeleton contains carotenoids (which are pigments) called astaxanthin. It is these carotenoids that are what give salmon its pink color. Before the shrimp is cooked the astaxanthin is covered by protein chains called crustacyanin. The protein chains in fact wrap up the astaxanthin, concealing its lovely pinkish-red color.
But heat loosens the hold these protein chains have on the carotenoids and releases the astaxanthin, turning the shrimp its lovely shade of pink. This is the same reason lobsters turn red when you cook them.
One more fun fact: if you've ever heard that flamingos are pink because they eat shrimp, it's because of this same carotenoid. While flamingos eat shrimp that still appear blueish gray (they don't have the luxury of cooking them before eating), the crustacyanin protein chain dissolves in digestion ― releasing the carotenoid that makes flamingo feathers more pink.
Now that you know why, watch the magic happen with these shrimp recipes.