Except for those who repent, correct themselves, hold fast to Allāh, and are sincere in their religion for Allāh, for those will be with the believers. And Allāh is going to give the believers a great reward.
Allah forbids His believing servants from taking the disbelievers as friends instead of the believers. This includes being friends and associates of the disbelievers, advising them, being intimate with them and exposing the secrets of the believers to them. In another Ayah, Allah said,
(Let not the believers take the disbelievers as friends instead of the believers, and whoever does that, will never be helped by Allah in any way, except if you indeed fear a danger from them. And Allah warns you against Himself). meaning, He warns you against His punishment if you fall into what He has prohibited. This is why Allah said here,
The purpose in previous verses was to point out to some ugly traits of the hypocrites, though their punishment of being in Hell with disbelievers was also mentioned as a corollary to another subject.
From this stage onwards, the purpose is to state their punishment clearly. Since the inherent effect of such impending punishment generates a sense of fear in a good-natured person which usually becomes the reason for early repentance, therefore, exemption from punishment has been promised to those who repent alongwith the incentive of good reward for them.
The Meaning of sincerity
The statement: وَأَخْلَصُوا دِينَهُمْ (Make their Faith pure for Allah) in verse 146 shows that a deed in order to be acceptable with Allah has to be free of hypocrisy and exclusively for His sake and pleasure, for Muslim jurists have enunciated the meaning of Mukhlis (translated with the weaker equivalent 'sincere' ) as follows:
A sincere person is one who acts for Allah alone and does not like that people praise him for it. (Mazhari)
Tazkirul Quran
Maulana Wahiduddin KhanOn ayahs 141–146
The hypocrite is one who is outwardly religious but inwardly irreligious. Having no principles, he watches out for opportunities to turn events to his own advantage. He associates himself with any group which may help him realise his worldly ambitions, be it composed of believers or of those who deny the truth. Into whichever gathering he goes, he speaks to please everybody. For reasons of worldly convenience or expediency he has to associate himself at times with believers, but he is not their well-wisher. Since the very existence of true believers becomes a criterion of Truth in a society, those who stand on the ground of false religiosity want such criteria as expose their false religiosity to be demolished. However, the evil wishers of the believers can make mischief only in this world. Believers will be safe from their mischief in the Hereafter. A hypocrite is bracketed with those who deny the truth, because in God’s judgement, there is no difference between outward religiosity and blatant irreligiosity. This is because although both the states may appear to be different, in reality they are identical. To God, what is of importance is the inward state (the reality) and not the outward appearance.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.