Depression, in its presently accepted clinical form might not have been necessarily known prior to its formulation in the early 20th century, but various psychological and psychosomatic conditions to large extent compatible with the depression as we know it are known and recognized as a condition for several millennia. Regardless of the character, attributed causes and methods of healing, we can state with substantial certainty that the symptoms of depression and other psychological conditions have been known and addressed for a very long time.
I will limit myself to the periods preceding the actual development of the modern understanding of depression in late 19th and 20th century, as it is not really that related to topic due to the common acknowledgement of depression in medical community within that period.
The oldest texts speaking of the conditions that could be construed as depression according to the DSM-5 or ICD-11 (modern psychological diagnostic manuals) come from the Ancient Mesopotamia. For example, a text catalogued under the signature AMD 8/1 8.6 speaks of the following situation that bears a resemblance to a clinical depression.
He develops sadness/his spirit is low/he says 'woe' and shouts 'alas!'/his appetite for food and drink wanes, so does his need to go towards a woman, his spirit does not lead him to a woman/he says 'have pity on me'.
In this case the word rendered as 'spirit' is libbu that much as the word temu refers to an immaterial, divine part of the human being, similar to concept of 'soul', 'reason' or 'spirit' (please note the German word 'Geist' is still used to denote psyche and spirit [both as the human soul and apparition from beyond the grave]).
Likewise, another text from the same region, suggested to be written somewhere in 16-17th century BCE and presented under the signature BAM 234 by Köcher. The original text goes as follows (English version after Reynolds and Wilson):
If the head of a household has had a long spell of misfortune – and he does not know how it came upon him – so that he has continually suffered losses and deprivation (including) losses of barley and silver and losses of slaves and slave-girls, and there have been cases of oxen, horses, sheep, dogs and pigs, and even famiy members dying off altogether; if he has frequent hip libbi (lit. 'breaking of the spirit', possibly a nervous breakdown), and from constantly giving orders with no one complying, calling with no one answering, and striving to achieve his desires while having to look after his household, he shakes with fear in his bedroom and his limbs have become “weak”; if because of his condition he is filled with anger against god and king; if his limbs often hang limp, and he is sometimes so frightened that he cannot sleep by day or night and constantly sees disturbing dreams; if he has a “weakness” in his limbs from not having enough food and drink; and if he forgets words, then, as for that man the anger of gods is upon him.
Please note that the description of the condition is quite consistent with the common underlying causes of the exogenous (reactive) depression disorder, i.e. one resulting form intense, combined or prolonged stressors (most often than not combination of all three), such as financial loss, death of relatives, perceived lack of respect or failure to meet one's standards and resulting feeling of inferiority or inadequacy. This is followed with clinical symptoms, starting from anxiety, exhaustion, insomnia or lack of focus and even including severe ones, such as hallucinations, noticeable mental deterioration or lack of appetite leading to malnourishment. In other words, Mesopotamian text quoted above presents detailed if very severe (possibly in an attempt to show all known symptoms at once, maybe as a kind of medical instruction) description of a clinical depression.
In both cases presented above, much like in other, similar to these, what we would call today psychological condition was eventually attributed to the influence of the gods, although the actual external stimuli also played a role in the development of the illness. Methods of healing associated with the conditions were pretty much limited to the religious rituals, incorporating prayers and offerings.
Symptoms of depressive disorder were observed also by the Greek scholars, such as Aristotle and Hippocrates, who tried to explain them by the imbalance of humours, attributing relatively weakened state associated with inactivity, sadness (dysthymos) and anxiety (phobos) by the excessive amount of the 'black bile', thus coining the term 'melancholy' (from Greek 'melas' and 'khole' meaning 'black' and 'bile' respectively). This assumption, although generally incorrect due to the purely theoretical and non-factual concept of the bodily humours, was nevertheless one of the first, if not the first theory linking the psychological conditions to the incorrectly working human body or, as we would put in modern medical parlance, the somatic cause of the psychological conditions. Hippocrates mentions that as temporary sadness is a normal reaction to a loss, melancholy can be differentiated by excessive length or lack of any discernible trigger for the diminished mood, which are basic differences between depression and temporarily abated affect. These observations were also echoed by Aretaeus of Cappadocia who lived in 2nd century CE and pointed out that 'melancholic patients' are not only sad or exhausted, but also stern, serious and torpid although they lack any immediate reason to express any sadness or grief.
An interesting case of diagnostics that is professional even for modern standards comes from the works of Galen, who recounts a case of apparent insomnia and from the behaviour of the patients guesses not only that she might suffer not only from melancholy (depression) but also from some other psychological problem she is unwilling to disclose. Consciousness of working with an incomplete set of data and possible error in diagnosis shows a high level of professionalism on account of Galen.
I was called in to see a woman who was stated to be sleepless at night and to lie tossing about from one position into another. Finding she had no fever, I made aa detailed inquiry into everything that had happened to her, especially considering such factors as we know to cause insomnia. But she either answered little or nothing at all, as if to show that it was useless to question her. Finally, she turned away, hiding herself completely by throwing the bedclothes over her whole body, and laying her head on another small pillow, as if desiring sleep. After leaving I came to the conclusion that she was suffering from one of two things: either from a melancholy dependent on black bile, or else trouble about something she was unwilling to confess. I therefore deferred till the next day a closer investigation of this. [transl. by A.J. Brock].
Medieval doctors were generally following and elaborating on the instructions given by Antique authorities, chiefly Aristotle, Hippocrates, Galen and Paul of Aegina, both using the original Greek sources and their versions expanded by the Muslim scholars. In addition to the general understanding of melancholy, a concept of acedia was also commonly discussed in the context of what we would call today a clinical depression. One can argue that the condition described as acedia by the philosophers of late Antiquity and early Middle Ages was to large extent a form of depressive disorder or even an early observation of the manic-depressive (bipolar) disorder. Although commonly translated to English as 'sloth', as in one of the Cardinal Sins, it was generally far more complex condition, that in its various descriptions bears a resemblance to the axial symptoms of depression. For example, Evagrius of Pontus, 4th ccentury Christian philosopher described acedia as a state in which people are unable to start any meaningful task even if they actively try to do so (and starkly differentiates it from slothful disposition), are permanently exhausted and insomniac at the same time, can't focus on any action, and whatever they do, they rarely if ever find any pleasure in it, because 'they do not really know what they want to do' (what is consistent with anhedonia and attention deficit, often associated with clinical depression). Evagrius also notes that this state is usually accompanied with feeling of helplessness, sadness and bouts of crying. Religious notions were also found much later, as e.g. in the works of Johann Christian Heinroth written in 1820s and 1830s, where the author proposed the idea that the melancholy is an affliction of the soul caused by the 'moral conflict' within the patient, what, although the difference in wording is quite distinct, corresponds very well to the modern concept of exogenous depression that is largely caused by the interaction of psychosocial factors and the attitudes of the patients.