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.