Most chemicals in nature have no colour. The thing that gives something a colour is the way it absorbs light. Chemicals are the colour opposite of the colour they absorb. The absorption of colour happens through a complex interaction of the vibration energy of electrons that involves quantum theory and a lot of hard math. When phenolphthalein is in basic solution (as opposed to acidic solution) a couple of hydrogens are pulled off its molecular structure in such a way that a ring of carbon atoms opens up to create what is called a highly conjugated bond structure in the molecule. That means that the chain of carbon atoms making up the phenolphthalein molecule alternate with single bond and double bond connections between each carbon. This alternating single, double, single, double bonding system often results in colour because it creates conditions that give just the right vibrations to the electrons so they absorb energy in the rather narrow part of the electromagnetic spectrum that we humans can see. For more detail, there's a great explanation at General Chemistry Online.
making a small donation to science.ca.