Personally, since I was a teenager with depression, I realized two things.
The first is a psychological need to feel loved because when we are depressed, we unconsciously need affection, since we are humans, we have emotions and sensations that make us seek/compensate for a need, whether real or not (since it is part of our mind).
On the other hand, regarding the sexual. Being addicted to porn, I realized that when I was depressed, I sought to obtain those sensations that would generate "pleasant brain substances" that would reduce my pain. Obviously it is unconscious, it is not like I have known it, but it is also a form of survival, because in the form of depression and thoughts of death, the reproductive need, as in animals, makes us feel that in this case, by instinct or awareness of our mortality, we seek to reproduce and therefore it is a mere survival mechanism, rare but with a more biological than even rational meaning (wanting to be in a relationship and feel loved, having children with someone, etc.).