From a physical standpoint pain and depression share much of the same biochemistry of the brain. Equally as important, they both interfere with sleep.
The medication taken for pain also often disrupts sleep.
The inability to control pain leaves a patient with a sense of helplessness, and from a psychological standpoint, the learned helplessness is the cornerstone of depression.
Additionally, knowing that a patient is powerless even to sleep-away-pain, leaves the patient feeling powerless and out of control. The patient will then nap during the day due to sleep deprivation at night.
Since narcotic pain medication can result in unusual, if not bizarre, dream content, it is not unusual for pain patients to have nightmares in which they are being harmed or otherwise physically suffering.
Thus, sleep and pain become entangled. Upon awakening, they are still tired, and left with the aftermath of unpleasant dreams and a painful night.
Patients then become irritable toward family and health care providers, often driving away the very support they need.
Often an indirect, but effective means, of treating pain is treating the depression that accompanies it.