A prison is a room made from a restraint(v). It can be a rope or a chain. Criminals are put there for a time decided by either the Hammerer or the Baron, and it's usually due to throwing tantrums or failing mandates. The "Failing Mandates" is a dangerous one as it tends to hit your legendary artisans, which is why you WANT a prison, or the Hammerer will simply kill them.
Now, there is however an "exploit" of sorts to avoid this problem all together. You can simply NOT appoint a Sheriff/Captain of the Guard, and you will never get a Hammerer and the whole problem goes away entirely.
As I said, nobles are somewhat buggy at present.