Medieval castles and dungeons tend to go together in people's imaginations and I have set important scenes in A Knight's Enchantment in a dungeon, where the heroine Joanna's father is being held. What we imagine as a typical dungeon, however - dark, underground, no windows, lots of chains - was less common in the Middle Ages than is assumed.
Take the word 'dungeon'. Its earliest form, donjon, meant a keep or tower, a strong defensive position. Over time that tower has been taken to mean a prison, often
underground in a castle. This form of prison was in fact an oubliette (meaning 'forgotten place') and was far darker and more grim than a dungeon, as can be seen in the photo of the oubliette in the castle at Warwick.
Famous dungeons include the Tower of London and those at Pontefract Castle and Alnwick Castle, though true dungeons in castles were not usual until later in the Middle Ages.
Often noble prisoners, captured and held for ransom in the dungeon, would be kept in a secure, comfortable place within the host's castle: certainly the room would be well-guarded, but we should not picture a Richard the Lionheart or Charles of Orleans languishing in the rat-infested, damp stone cell of imagination. Life expectancy in an oubliette would be short, and bad for the ransom business. 'Common' prisoners might be kept in gate houses, while those considered undesirable and disposable but not to be actually murdered could end up down with the rats in the oubliette.