All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallahu ʻalayhi wa sallam, is His slave and Messenger.
In an authentic hadeeth, the Prophet, sallallahu ʻalayhi wa sallam, said, “Perhaps Allah has looked at those who witnessed Badr and said, ‘Do whatever you like, for I have forgiven you.’” [Al-Bukhaari and Muslim] Another version of the hadeeth reads, “...for Paradise is guaranteed for you.” The meaning is obvious; that Allah decreed for the Companions who participated in the Battle of Badr that they shall be among the people of Paradise and that the sins which they commit are forgiven.
The fact that the Prophet, sallallahu ʻalayhi wa sallam, lashed Mistah, may Allah be pleased with him, for slandering ʻAa’ishah – and he was one of the people of Badr – or that ʻUmar lashed Qudaamah ibn ʻAbdullah, may Allah be pleased with him, for drinking alcohol – and he too was one of the people of Badr – is not contradictory with the hadeeth, because the forgiveness of sins mentioned in the hadeeth is not necessarily without a reason. It might very well have a reason, such as receiving the Hadd (corporal punishment prescribed for a crime, like lashing).
Shaykh Al-Islam Ibn Taymiyyah wrote in this regard:
“For example, the hadeeth of Haatib ibn Abi Baltaʻah, may Allah be pleased with him, wherein he (the Prophet ) said to ‘Umar, ‘Perhaps Allah has looked towards the people of Badr and said, 'Do whatever you like for I have forgiven you.'’ It was narrated that a slave of Haatib complained of him, saying, ‘By Allah, O Messenger of Allah, Haatib is going to enter Hellfire!’ The Prophet said, ‘You have lied! He has witnessed Badr and (the treaty of) Al-Hudaybiyah.’ These ahaadeeth underline that the believer may carry out good deeds that would be the reason for having his future sins forgiven even if such forgiveness is realized through other means. They also indicate that such a believer shall die while adhering to Imaan (faith) and will be admitted to Paradise. Were he to commit a sin, he would repent to Allah and Allah would forgive him, as He forgave the sins of the Companions who participated in the Battle of Badr. An example is Qudaamah ibn ʻAbdullah, may Allah be pleased with him, who drank alcohol based on a figurative interpretation of the relevant verses. ʻUmar, may Allah be pleased with him, gave him respite to repent of his sin and then subjected him to the prescribed Hadd. He was lashed and cleansed of his sin through the Hadd and through repentance, although he was one of those who were told, ‘Do what you like...’ The promised forgiveness does not negate the fact that this person may earn such forgiveness through other means; it could be realized through his repentance. The essence of the promised forgiveness is that Allah shall not punish him after death as He knows of this sinner's intention to repent. If Allah knows his intention to repent of his sin or to carry out good deeds to have his misdeeds forgiven, Allah will forgive his sins... Mistah, who was the relative of Abu Bakr and participated in the Battle of Badr, took part in the incident of Slander against 'Aa’ishah, so he was one of those whom Allah addressed in the verse: {Indeed, those who came with falsehood are a group among you. Do not think it bad for you; rather it is good for you. For every person among them is what (punishment) he has earned from the sin...} [Quran 24:11] And the verse: {When you received it with your tongues and said with your mouths that of which you had no knowledge and thought it was insignificant while it was, in the sight of Allah, tremendous.} [Quran 24:15] And: {Indeed, those who (falsely) accuse chaste, unaware and believing women are cursed in this world and the Hereafter; and they will have a great punishment.} [Quran 24:23]
It was authentically reported that the Prophet, sallallahu ʻalayhi wa sallam, lashed this Companion for his role in the incident of Slander; however, there is no doubt that he repented to Allah. This indicates that the Prophet's words, ‘Allah has forgiven you,’ in the hadeeth do not mean that those Companions, who participated in the Battle of Badr, would not commit sins and repent of them afterward. Rather, this must be the case; otherwise, they would have relied on this promised forgiveness and would have neglected the means to forgiveness; namely repentance and good deeds that wipe out past sins, or other means for having one's sins forgiven, such as the calamities and afflictions in the worldly life, in the Barzakh (the period between death and resurrection), or on the Day of Judgment, or through His mercy. Those means are common to those who know that their sins are forgiven as well as those who do not know but who know that Allah forgives whoever repents to Him and that He admits him to Paradise.” [Summarized]
Allah knows best.