The word dungeon comes from French donjon (also spelled dongeon), which means "keep", the main tower of a castle. The first recorded instance of the word in English was near the beginning of the 14th century when it held the same meaning as donjon. The proper original meaning of "keep" is still in use for academics, although in popular culture it has been largely misused and come to mean a cell or "oubliette". Though it is uncertain, both dungeon and donjon are thought to derive from the Middle Latin word dominio, meaning "lord" or "master".
In French, the term donjon still refers to a "keep", and the English term "dungeon" refers mostly to oubliette in French. Donjon is therefore a false friend to dungeon (although the game Dungeons & Dragons is titled Donjons et Dragons in its French editions).
An oubliette (same origin as the French oublier, meaning "to forget") was a form of prison cell which was accessible only from a hatch or a hole (sometimes called an angstloch) in a high ceiling. The use of "donjons" evolved over time, sometimes to include prison cells, which could explain why the meaning of "dungeon" in English evolved over time from being a prison within the tallest, most secure tower of the castle into meaning a cell, and by extension, in popular use, an oubliette or even a torture chamber.
The earliest use of oubliette in French dates back to 1374, but its earliest adoption in English is Walter Scott's Ivanhoe in 1819: "The place was utterly dark—the oubliette, as I suppose, of their accursed convent."