Yep! Before modern antidepressants were discovered, opiates were sometimes prescribed for depression and other mental disorders. And they're still prescribed as cough suppressants, anesthesia meds & anti-diarrheal agents for severe IBS and IBD. Heroin was once thought to be a miracle cure for cocaine and morphine addiction. (Most modern drugs of abuse were once considered miraculous and prescribed for everything under the sun).
There's an opiate antidepressant in the pipeline as we speak: ALKS-5461. It contains buprenorphine and an opioid blocker, making it similar to Suboxone.
Here's a study on oxycodone and oxymorphone for refractory depression.
Would today's typical psych doc prescribe opiates for a mental illness? 99 times out of 100, the answer is hell no. And with good reason: addiction makes your problems infinitely worse.