The Ramban in Devarim 22:6 states that the mitzvos are for our own good. Hashem gains nothing from any of them. 

Therefore not only do we do harm to others when we sin, but we actually distance and destroy our connection with Hashem. We damage ourselves too! Hashem is constantly trying to shower us with all good, but we distance ourselves with our free choice. (See Ramchal Derech Hashem Chapter 4:10)

Gehinom is there to purify us from this harm.

Please see Chagiga 15b. 
Acher a sage sins horribly, he may not enter the world to come because of the sin, he may not enter punishment because of his Torah.
Rebbi Meir mentions it would be better for Acher to face judgement (ie: Gehhna smoke pours from Acher's Kever) so that he should be able to enter the world to come. And that is precisely what Rebbi Meir causes to happen. We see a clear example (imo) that the "punishment" is for our benefit as well so that we may enter the world to come. Acher was not allowed to enter that world since he sinned, but after his punishment he is. The sin has been purified.

Also the punishment is limited in duration (12 months) See Sefer HaIkarim 4:38.