Hair can’t turn gray overnight, but a head of hair can go gray very quickly when a person has a lot of gray already and loses all the dark hair.
Hair is made of dead cells, and you can’t change the color in a dead structure unless you dye it.
However, if a person is graying, the remaining dark hairs may be in the resting phase of the hair cycle while the incoming hairs are both gray and growing.
The resting hairs would normally fall out in the course of time, but after a severe insult, like a car accident or surgery or even the death of a loved one, the resulting stress can cause the resting hairs to fall out all at once.
Why graying occurs at all is not entirely clear, but it runs in families and may be treatable once the cause is found.