The Israelites were forgiven only when they had offered Taubah توبہ (repentance), as recounted in Al-Baqarah 2:54 ⧉. In saying that they were pardoned so that they might learn gratefulness, the present verse Al-Baqarah 2:52 ⧉ employs the Arabic word لَعَلَ La` lla which indicates expectation. In the present context it does not mean that Allah had or could have any doubt or misgiving about this or any other matter; what the word implies here is just that when a man receives a pardon, the onlookers may expect him to feel grateful.