The first attestation of the word dungeon was in the 1400s, but there were a whole lot of variations in Middle English: it was also recorded as taking the forms dungeoun, dungoun, dungun, and dongoun, among others. All of these words either meant "tower", "keep", or had our modern definition of "dungeon". The reason all these incongruences existed was because dungeon is an inherently incongruent word. The truth is, it's an amalgam of the French word donjon, meaning "keep" (the main fortified tower of a castle), and the Old English word dung, meaning "prison". Together, they would make "castle prison" or "dungeon"- and this was a much-needed word at the time, so they were mashed together in every which way until we finally settled on a standard spelling. Dung is not the excretory dung you immediately think of; through Proto-Germanic, it comes from Proto-Indo-European deng, meaning "to cover". Donjon might have Frankish origins. If so, it would be from Proto-Germanic dungo, meaning "enclosed space", which ironically also hails from PIE deng, "to cover". So combining dung with donjon is just saying "cover cover", but that's what it is!
Adam Aleksic, a rising sophomore studying linguistics and government at Harvard University, has been described as the internet's sixth most famous etymologist. He also has disturbing interests in politics, vexillology, geography, board games, conlanging, and law.