Blue devils referred to the upsetting hallucinations brought on by severe alcohol withdrawal.
Shortened to the blues it described states of depression and upset, and it was later adopted as the name for the melancholic songs that the musical genre encapsulates.