Yes if someone's depression is severe enough then a doctor may prescribe Xanax to treat depression.
My sister has severe depression and does take Xanax for it and it does help her greatly with the depression.
Xanax works to treat depression by changing the neuron activity in the persons brain.
Xanax is the third most prescribed depression medicine in the world so it does work.