Prison is represented as a positive part of Raskolnikov's process. Even before he turns himself in to the police, he doesn't seem afraid of prison and looks at going as a kind of relief. Sonia seems actually eager to follow him there. (Though she was probably just happy to get out of St. Petersburg.)
When Raskolnikov gets sick in Siberia, it's made clear that it's not because of "the horrors" of prison life, it's because the other prisoners want to kill him and because he's not sure that there's any real purpose to his punishment. In short, he's still ultra-isolated from the community in which he lives.
So he gets sick and is admitted to the prison hospital. This is the first time he's been in a place that's only purpose is to heal the sick. When he gets sick before, he has a doctor, but the place of healing is the same awful room that made him sick in the first place.
The prison hospital becomes, for Raskolnikov, a place to begin to recover. It is there that he has the dream about a virus that invades all of humankind, which causes them to cling madly and fanatically to whatever ideas they were attached to when they came in contact with the virus.
This is the first dream which actually releases his tension, his anxiety over what he had done. In the world of the dream he sees his own fanatical clinging to an idea reflected gruesomely and, thereby, made clear.
When he is "almost well," he sees Sonia at the prison gate, from the window, and, "Something stab[s] him to the heart at that minute" (Epilogue.2.19). This is something new. He is discovering that he really does love Sonia. When he gets out of the hospital, this immediately intensifies, and suddenly even the prisoners seem friendlier. After healing in the hospital, Raskolnikov is no longer an alien in his community.