Rehabilitate might not be the best word here, seeing as some criminals cannot be restored to 'normal', since they were never 'normal'.
Anyway, the aim of rehabilitation is to alter the behaviour of the criminals so that they will not commit any further crimes.
Punishments are used as deterrents, that is, they are used to alter the behaviour of the one being punished, so that they will avoid the action that caused the punishment in future. As such, the two are not mutually exclusive.
That said, imprisonment should not be used as just a punishment, rather, it should be used to rehabilitate the prisoner as best as possible, perhaps using punishments to further that goal.
Anyway, the aim of rehabilitation is to alter the behaviour of the criminals so that they will not commit any further crimes.
Punishments are used as deterrents, that is, they are used to alter the behaviour of the one being punished, so that they will avoid the action that caused the punishment in future. As such, the two are not mutually exclusive.
That said, imprisonment should not be used as just a punishment, rather, it should be used to rehabilitate the prisoner as best as possible, perhaps using punishments to further that goal.