The story
The phrase is influenced by the popular belief that stress can cause the greying of hair (that link wasn't shown to be grounded scientifically until a January 2020 study on stress in mice for the Nature journal).
Etymology from Wiktionary, CC BY-SA 4.0.