Can a creature cast spells while it is restrained by Imprisonment?
The answer to this is different for each form of Imprisonment. There is no overall restriction on casting spells, though divination spells won’t work on the target of the Imprisonment. For instance, an imprisoned character would not be able to Detect Magic or Identify any effect/item on themselves, though that would not stop them from casting the spells.
Looking at each form:
Imprisonment PHB p.252
Burial. The target is entombed far beneath the earth in a sphere of magical force that is just large enough to contain the target. Nothing can pass through the sphere, nor can any creature teleport or use planar travel to get into or out of it.
The sphere of force is just large enough to contain the target. This implies that the target is trapped in a ball just big enough for them to be curled up into. They do not have the restrained or any other imposed condition. There is no explicit restriction on casting spells. It is the DM’s call whether they have the space to use material or somatic components to cast spells, but verbal components are unrestricted. I would judge that they don’t have the space to use their hands unless they can make a difficult escape/acrobatics roll, but this is opinion based. Regardless of this nothing can pass through the sphere of force, not even by using a different plane of existence, so you cannot target anything outside of the sphere of force.
Chaining. Heavy chains, firmly rooted in the ground, hold the target in place. The target is restrained until the spell ends, and it can’t move or be moved by any means until then.
The target is restrained. There is no stated restriction on casting spells and the restrained condition does not restrict casting. Any spell cast that attempts to move the caster in any way will fail to do so. It is the DM’s call whether a character has the freedom of movement to use their hands to cast spells. Verbal components are unrestricted. I myself would judge that they are able to use their hands to cast, but this is opinion based.
Hedged Prison. The spell transports the target into a tiny demiplane that is warded against teleportation and planar travel. The demiplane can be a labyrinth, a cage, a tower, or any similar confined structure or area of your choice.
There is no restriction on casting spells. The ward against teleportation and planar travel will cause spells of this type to fail. It is the DM’s judgement whether this ward just denies travel into or out of the plane, or also to any such travel within the plane. I would judge that the it is the border of the plane that is warded so it only applies to travel into or out of the plane, but this is opinion based.
Minimus Containment. The target shrinks to a height of 1 inch and is imprisoned inside a gemstone or similar object. Light can pass through the gemstone normally (allowing the target to see out and other creatures to see in), but nothing else can pass through, even by means of teleportation or planar travel. The gemstone can’t be cut or broken while the spell remains in effect.
There is no restriction on casting spells. However many will fail due to the absolute restriction against anything passing through the wall of the prison except for light. I would judge that certain light based spells that originated at the caster would work, e.g. Color Spray PHB p.222, but nothing else can pass through the containment, not even by using a different plane of existence, so you cannot target anything outside of the containment.
Slumber. The target falls asleep and can’t be awoken. The special component for this version of the spell consists of rare soporific herbs.
Obviously the character is not capable of casting.