imam nawawi in his minhaj [sharh muslim 2/141] said after citing qadi iyad's opinion [below]: ibn baTTal and other research scholars [muHaqqiqin] that the hadith is taken literally. that is, if a kafir becomes a muslim and dies upon faith [on islam], he will be given reward for his good actions that he did while he was a kafir. they cited the hadith of abu sayid al-khudri raDiyAllahu anhu in which RasulAllah sallAllahu alayhi said: when a kafir becomes a muslim, and his islam is good [i.e. he becomes a good muslim] Allah ta'ala will Inscribe for him for every good deed that he did in his past - and erase all his bad deeds and sins done in the past; and his good deeds thereafter [becoming a muslim], for every good deed his reward will be 10 to 700 times; and recompense for sin will be one is to one. this was mentioned by dar quTni in 'uncommon reports of malik' and reported by malik via 9 different routes and established in them that a kafir when becomes a muslim [and is steadfast as a muslim], every good deed he did in his state as a polytheist will be written for him [i.e. merits reward]. ibn baTTal after mentioning the hadith said: 'it is for Allah taala to bestow His favours upon His slaves, as much as He likes. no one has the right to object.' and he said: 'this is similar to the saying of RasulAllah sallAllahu alayhi wa sallam to Hakim ibn Hizam raDiyAllahu anhu: 'you became a muslim for the past in which you did good deeds'. Allah ta'ala knows best.