If you're in the United States, you're options are severely limited when incarcerated, either in Jail or Prison. The medications and treatment that you will receive will vary heavily dependent upon the Dr. and the rules of the institution. I've heard that it's not commonplace for narcotics to be prescribed, with or without an existing prescription, but again, this varies on a case by case basis. For instance, I think a terminal cancer patient will likely get Opioids, whereas someone with a bad knee might end up toughing it out.
Really you need to plan on withdrawing before you get to prison if you do go. Being sick in the comfort of your own home is definitely preferrable to doing it in a cell. You will likely be provided an NSAID for the aches and pains and if you go for a couple of weeks straight without sleep, you might be prescribed some Quetiapine (Seroquel).
I would highly suggest figuring this out before you go. All joking aside, withdrawing from Opioids in jail was probably the worst, most nightmarish experience of my life.
Just for a point of reference, I believe there are 2-3 total institutions in the US that offer maintenance therapy.