I had absolutely no idea! This information got me searching for more information about it. This is what I found out..
Fish have cells called chromatophores that produce the pigments that give coloration or reflect light. Fishes get their different colours due to various factors such as; which pigments are in the cells (there are several colors), how many pigment molecules there are, and whether the pigment is clustered inside the cell or is distributed throughout the cytoplasm.
What happens to the goldfish is that when it is kept in dark room the chromatophores won’t produce any pigment. So the fish’s color will start fading as the chromatophores that already have color naturally die, while the new cells aren’t stimulated to produce pigment because of the lack of light. And THAT is how it works : D
BTW I have also read that goldfishes kept in darkroom needn’t always turn white coz of some other factors. Fishes also get their coloration from the food they eat.