To be quite clear, I don't believe that prison's sole value is a deterrent. I think there's an element of justice (criminals should have to pay for their crimes), an element of deterrence (prison should make criminals think twice--this feels intertwined with 'justice' and yet distinct), an element of rehabilitation (to the extent that we can rehabilitate prisoners, we should), but mostly I think there is significant social value in protecting innocent people by keeping harmful people away from innocent people.
Even if the deterrent effect is nil and even if you don't believe in justice (or for many of my fellow liberals, you reserve 'justice' for crimes that offend you, such as white collar crimes), I would still keep prisons around for the protection of the innocent. That said, I have an optimistic view on the potential for prisons.
But countless studies have shown that it's not an effective deterrent.