Yes inmates in prison and jail are locked into their cells at night to prevent escapes.
If the inmates jail cells or prison cells were left unlocked at night then the inmates could more easily escape or do harm to the guards during the night.
So around 6:00 PM usually all inmates are sent to their prison cells or jail cells and they are locked in for the rest of the night and then by either 5:00 AM or 8:00 AM the prison cells or jail cells doors are unlocked and the prisoner is allowed to come out into the day room where they can roam about or watch TV or do their jobs.
If the prisoner is in a maximum security prison then they may remain locked in their prison cells for 23 hours per day and only allowed out of their prison cells for 1 hour per day to go out into a rec cage.
Some prisoners who are in less security may be allowed outside most of the day if the weather is nice in a recreation yard where they can play basketball or just walk around or sit around out in the sun.