It originated from the name of the male reproductive organ. It is the same shape and in some cases it is probably the size of yours if you are a guy reading this. Don't get fooled by pen and penis. Don't forget to put a space after pen when it is followed by the verb is, otherwise you would have spelt penis. See exemple below.
A prison, penitentiary, or correctional facility is a place in which individuals are physically confined or interned and usually deprived of a range of personal freedoms. Prisons are conventionally institutions which form part of the criminal justice system of a country, such that imprisonment or incarceration is the legal penalty that may be imposed by the state for the commission of a crime.
What can we do when we're arrested, but open fire
Life in the pen ain't for me, cause I'd rather die - Tupac