I'm fairly sure this was a Star Trek episode. A character went through a horrible prison experience for years, only to find out when he woke up that merely months had passed and it was all part of some mind changing drug/process that the aliens had created to make the time served seem longer.
The character was constantly starving his cellmate, then one day they became angry with each other and he killed his cellmate thinking he was withholding food from him, only to find after the murder the cellmate had been saving food for him?