Why does cooked ham stay pink while ordinary pork turns gray-brown?
Sodium nitrite isn't a pink dye. During curing, nitrite can generate nitric oxide, which binds to the iron-containing heme of myoglobin. Heating then produces a relatively stable pink cured-meat pigment.
Nitrite also helps inhibit Clostridium botulinum, but its reactive nitrogen chemistry can contribute to nitrosamine formation.
The pink color is coordination chemistry around iron already present in the meat.