When was incarceration used for the first time as a penalty for criminals?

The Romans used prisons around 640 BC. The Mametime Prison was one of the first at that time, having horrible environment for the prisoners, such as contamination with human waste. Prisoners were held in squalid conditions.