Only the system as a whole must carry superior fitness, not each of its individual components. Given a sufficiently complex system, its rather expected that there will be negative, or even outright destructive functions that arise. You can certainly try to find a positive reason for why cancer, disease, death during conception, etc exist, but there is a much simpler explanation.
Depression in this view, isn't something outright that was adaptively constructed, but merely a side effect of how the mind works.