Sometimes you can infer from evolution that a trait is useful. But only if the trait:
1. Is in a stable part of the genetic code, giving opportunity for bad traits to be weeded out.
2. Is not correlated with a different useful trait that overshadows its goodness/badness.
3. Shows up early enough to affect reproduction.
Human intelligence is quite recent, so prerequisite #1 is not met. We have no idea if prerequisite #2 is met, and prerequisite #3 is met.
So natural selection can't tell us if depression is/was useful. The kinks of human intelligence are not yet worked out.