New research on depression may throw some light upon the way transgender and nonbinary people experience depression. In "We’ve Got Depression All Wrong. It’s Trying to Save Us," Alison Escalante argues that depression may be part of a biological survival strategy.
Normally depression is seen as a negative side effect of emotional trauma, abuse or some random physiological or medical factor. Depression is not seen as something functional or meaningful per se.
However, I have seen research that tries to explain depression as an attempt to achieve the social isolation needed for healing and recalibration.
This article takes this argument one step further: Depression leads to a kind of withdrawal that reduces the risk of violence and abuse from people around us. So in a dysfunctional family with an abusive parent or spouse, the body triggers a kind of inertia that may protect a person agains physical or emotional violence.
When the inner need for growth collides with people's desire to conform
Think of it this way: We are all born with a need for self expression and self realization, which may lead to conflict with others. Good parents and good friends give people room to explore and express themselves (within reason).
Sociopaths, control freaks and people driven by fear of social exclusion may see such independence as a threat to their own hegemony and/or status in society. They will therefor use violence to curtail this freedom. They may even think of this as a way of "helping" the child.