Depressed people isolate themselves from the society because they see little value and/or pleasure in socializing and in the activities that other people would consider enjoyable.
This is a very prominent, common and major sign that the person is suffering from depression and ironically, only intensifies the depression further. This makes social withdrawal a depression trap, as well as a symptom.
The causes behind this behavior can be as varied as those behind depression, such as biological, psychological, genetic, substance abuse or emotional. Sometimes an event causing emotional trauma can induce a depressed state on an otherwise normal person. Such a state of mind could lead the person to withdraw from social activities for some time as a reaction.
Many diagnosed depressed people do not produce a neurotransmitter chemical known as serotonin in sufficient quantities, which hampers their ability to extract pleasure from activities usually referred to as enjoyable. This is why anti-depressant drugs target this chemical in order to influence the mood of the patient. This explains why depressed people refrain to socialize, as they do not see any value in that activity.
There is a tendency among depressed people to further bog themselves down by the burden of depression when they find themselves in such a mood. The best way to escape the depression trap of isolating from society is to consciously recognize it as a time like that and to avoid following such behavior.
If you find someone around you who is in a depressed mood, the best line of action would be to make them realize and understand that such behavior would only worsen their emotional state.
For serious cases of clinical depression and bipolar disorder with a history of such behavior, the assistance of a psychotherapist should be sought. Medical professionals could even prescribe medicines such as antidepressants and SRIs in order to control the problem.
In any case, it is never safe to self-diagnose a state of depression and professional medical opinion should be relied upon for treatment.