لِيَجْزِيَ اللَّهُ الصَّادِقِينَ بِصِدْقِهِمْ وَيُعَذِّبَ الْمُنَافِقِينَ إِن شَاء أَوْ يَتُوبَ عَلَيْهِمْ
...
That Allah may reward the men of truth for their truth, and punish the hypocrites, if He wills, or accept their repentance by turning to them.
Allah tests His servants with fear and shaking so as to tell the evil from the good, as each will be known by his deeds. Although Allah knows what the outcome will be before anything happens, still He does not punish anyone on the basis of His knowledge until they actually do what He knows they will do.
As Allah says:
وَلَنَبْلُوَنَّكُمْ حَتَّى نَعْلَمَ الْمُجَـهِدِينَ مِنكُمْ وَالصَّـبِرِينَ وَنَبْلُوَ أَخْبَـرَكُمْ
And surely, We shall try you till We test those who strive hard and patient, and We shall test your facts. (47:31)
This refers to knowing something after it happens, even though Allah knows it before it comes to pass.
Allah says:
مَّا كَانَ اللَّهُ لِيَذَرَ الْمُوْمِنِينَ عَلَى مَأ أَنتُمْ عَلَيْهِ حَتَّى يَمِيزَ الْخَبِيثَ مِنَ الطَّيِّبِ وَمَا كَانَ اللَّهُ لِيُطْلِعَكُمْ عَلَى الْغَيْبِ
Allah will not leave the believers in the state in which you are now, until He distinguishes the wicked from the good. Nor will Allah disclose to you the secrets of the Unseen. (3:179)
Allah says here:
لِيَجْزِيَ اللَّهُ الصَّادِقِينَ بِصِدْقِهِمْ
...
That Allah may reward the men of truth for their truth,
meaning, for their patience in adhering to the covenant they had made with Allah and keeping their promise.
وَيُعَذِّبَ الْمُنَافِقِينَ
(and punish the hypocrites), who are the ones who broke the covenant and went against the commands of Allah, for which they deserve to be punished, but they are subject to His will in this world. If He wills, He will leave them as they are until they meet Him (in the Hereafter), when He will punish them, or if He wills, He will guide them to give up their hypocrisy and to believe and do righteous deeds after they had been wrongdoers and sinners. Since His mercy and kindness towards His creation prevail over His wrath,
He says:
...
إِنَّ اللَّهَ كَانَ غَفُورًا رَّحِيمًا
Verily, Allah is Oft-Forgiving, Most Merciful.