Actually I had been thinking of a follow-up post along these exact lines: "what does an effective prison look like in a D&D world?"
The original posters question was so broad and so dependent on the individual DM's assumptions regarding the availability of magic that I hesitate to try to answer it. But I can answer your question.
It looks a lot like a medieval or ancient world prison and nothing like a modern prison. PC's would find it extremely easy to break out of modern prisons, and virtually impossible to break out of medieval or ancient prisons. The big difference, is a modern prison is designed to be minimally comfortable and convenient to the prisoner, where as in the ancient world they didn't have the money to bother with elaborate systems for containing prisoners so they used techniques that were simple but brutally effective.
Some things about ancient prisons:
a) Prisoners were generally kept in near total darkness. Light was expensive, and you couldn't waste it on prisoners. Total darkness means almost no line of sight and difficulty scrying.
b) Dangerous prisoners (young men, for example) were generally immobilized when confined using stocks, pillories, and cangues. Immobilized prisoners are generally unable to cast spells that have components or otherwise use abilities to save themselves. Immobilized prisoners can't overcome guards with their bare hands as always happens in the movies or with PC's confined but left with mobility. And it's fairly easy to design stocks and the like which can immobilize something of less than demigod strength.
c) High security was implemented by the simple method of making the room a closed pit, with access only from a trapdoor above. Generally speaking, this requires magic to break out of.
d) Most ancient legal systems relied on a presumption of guilt, and didn't really care about your rights unless you were an upper class 'citizen'. Foreigners or commoners had basically no rights, and if they were threatening in any way but for some reason you weren't going to execute them, it wasn't unusual to take the precaution of maiming the prisoner. Are you afraid the prisoner might be a wizard? Snip his tongue out of his mouth, gouge his eyes out, and cut off his hands. Let's see how dangerous the wizard is without the ability to use any spell components, read a spell book, or target anything that requires line of sight to the target. In D&D, this is an even more reasonable approach, because worse come to worse and you need to apologize, you could also procure magic to restore the lost body parts.
e) Keeping prisoners is expensive and in a subsistence society you'd never confine a prisoner for long. Most long term confinement had to do with economic crimes like bankruptcy or being a political threat but not having committed an actual crime. In many cases even then, confinement by way of slavery was better than keeping someone inactive and not contributing economically, so really only nobles who you couldn't enslave had any sort of confinement to a prison system. The people so confined weren't necessarily 'dangerous' in the sense of a felon, and tended to be on good behavior in hopes of winning their freedom. The vast majority of actual criminal acts were punishable by death, because society had no extra resources to devote to keeping a person alive if they were a threat to the health and prosperity of the society.
f) One thing that is true, is that the more ancient the D&D society, the more it would tend to accumulate an inheritance of magical solutions to common problems. Really ancient and wealthy D&D societies can confine even high level magic using nobles successfully in moderate comfort because some time in the past some archmage will have constructed prison cells or shackles or whatever for that purpose because he either ruled the land himself, or else owed a favor to whomever did.
In general, even a very poor and primitive society can confine high level PCs effectively once it gets the upper hand on them. Without outside help, PC's are only likely to escape from an enslavement situation where they are allowed tools to perform labor and given limited mobility. In that case, they can easily overcome the sort of guards that can be hired to watch them, and then leverage their magic to defeat foes just like this was some sort of dungeon (and in fact, that might be the idea). But if actually incarcerated by a society that isn't playing by the rules of drama, keeping them constrained is fairly easy.