Peace be with you Ahmad ,
In my humble opinion , any mental or physical illness can be a punishment from God or test or both. Allah knows best.
(2:155-157) We shall certainly test you with fear and hunger, and loss of property, lives, and crops. But give good news to those who are steadfast, those who say, when afflicted with a calamity, ‘We belong to God and to Him we shall return.’ These will be given blessings and mercy from their Lord, and it is they who are rightly guided.
There is a genetic predisposition to depression. Adversity and emotional deprivation also predispose to depression.
There is evidence that both drug and psychological treatment works in depression.