The short answer is “yes.” If someone’s mental illness is so acute as to make it impossible for the person to leave the house, say, or if the person will experience grave distress, then that impossibility excuses the person from his Sunday obligation.
On the other hand, regarding depression in particular, it might be advisable to encourage the person to go to Mass, as participation in social activities can be a help. (If the depression is that severe, the person should seek medical attention.)
(If you know someone like this, please mention it to the parish, so that a priest or extraordinary minister can bring Holy Communion, if the person so desires.)