It's been ages since I did this, so i may be wrong but I think its to do with when its hydrated, ionic bonds are formed and through the donation of electrons over bonds, partially filled shells are left. then electrons here can be excited and absorb certain wavelengths of light - resulting in the colour.
EDIT: (so if it absorbs everything but blue light wavelengths, it will appear blue)
in anhydrous there aren't these bonds so it's just white because there are no partially filled shells
same applies to things like precious gems, just depends on what metal is contaminating the crystal.