What is the purpose of punishments in the afterlife (Gehinom, kaf hakela, gilgulim, etc.)? Are all of them for cleaning up the person from the consequences of his bad deeds and therefore for his benefit? Or are there any instances where these are a kind of retribution/revenge?
if there are such instances, then how can we reconcile this with the notion of God being the furthest extreme of kindness.
(as implied in the book Tomer Devorah and explicitly stated in the tov halevanon commentary to Shaar Bitachon ch.2 factor #7 - That the one he trusts is absolutely generous and kind to those deserving and to those who are not deserving, and that his generosity and kindness is continuous, never ending and without interruption. (Tov Halevanon commentary: the most possible extreme of generosity and kindness... see there)