The whole idea of punishment is a childish daydream. ~ English novelist George Orwell
The recorded use of prisons dates to the 2nd millennium BCE. Incarceration was one of many punishments, all of which embraced punitive requital.
Americans distinguish between jail and prison, if not in facility or duration of stay, at least in intent. Whereas jail is detention before trial, prison is the confinement of convicted offenders.
Records of Egyptian prisons date from the period of the Middle Kingdom (2050–1786 bce). Adhering to the principle of Maat, pharaohs had a sacred duty to preserve public order. They and their servants could be neither capricious nor cruel.
Middle Kingdom pharaohs preferred public beatings and imprisonment to the death penalty. Ancient Egyptian prisons alternately resembled fortresses with cells and dungeons or labor camps. Prisoners were expected to work during their confinement; a practice not unique to Egypt. When Samson was imprisoned by the Philistines, he was put to work grinding corn.
Jail and prison were one and the same in ancient Egypt. Nor was there any differentiation of prisoners according to their offense.
Each prison had a warden and staff of guards and scribes. Meticulous records were kept. Prisons economically housed the criminal courts that tried the incarcerated.
Escape from prison was an additional, serious crime.
Contemporaneous civilizations in the Near East had similar practices to Middle Kingdom Egypt. The Babylonian code of Hammurabi provided for several kinds of punishment, including a variety of executions and lesser retributions, including mutilation. The early laws had little mention of prisons, but they were used for debt, theft, and bribery, and for rebellious slaves and foreign captives, as was the practice in Egypt.
The Assyrian empire in 8th century bce imprisoned smugglers, thieves, deserters, and tax evaders. Like its predecessors in the region, foreign captives were a large part of the prison population. Forced labor was an integral part of the Assyrian prisons, which were located close to, or even inside, granaries. The Persian empire that succeeded Assyria had a similar approach to punishment.