All perfect praise be to Allah the Lord of the Worlds. May His peace and blessings be upon our Prophet Mohammad and upon all his family and companions.
Disclosing the secrets of the Muslims is among the major sins punishable with an exemplary punishment that suits the gravity of the crime itself. However, the Imam { Head of the Muslim community (ummah)} may consider the excuse as well as the motives of the perpetrator, then either pardon or punish him/her.
The companion referred to in this regard is called Hatib Bin Abi Balt`a (May Allah be pleased with him). Although, he sent a letter to the infidels informing them that the Messenger (Peace and blessings be upon him) and his army were marching towards them, he didn`t mean to betray the Muslims. Rather, his fear for the lives of his family members who were living amongst the disbelievers led him to do that in a bid to guarantee the safety of his family since they had no relatives to protect them. When the Prophet (Peace and blessings be upon him) realized the truth of the matter, he forgave him because he took part in the Battle of Bader since the companions who participated in the Battle of Bader enjoyed a special status over others. Narrated `Ali: Allah's Messenger (Peace and blessings be upon him) sent me, Abu Marthad and Az-Zubair, and all of us were riding horses, and said, "Go till you reach Raudat-Khakh where there is a pagan woman carrying a letter from Hatib bin Abi Balta' a to the pagans of Mecca." So we found her riding her camel at the place which Allah's Messenger (Peace and blessings be upon him) had mentioned. We said (to her),"(Give us) the letter." She said, "I have no letter." Then we made her camel kneel down and we searched her, but we found no letter. Then we said, "Allah's Messenger (Peace and blessings be upon him) had not told us a lie, certainly. Take out the letter, otherwise we will strip you naked." When she saw that we were determined, she put her hand below her waist belt, for she had tied her cloak round her waist, and she took out the letter, and we brought her to Allah's Messenger (Peace and blessings be upon him) Then `Umar said, "O Allah's Apostle! (This Hatib) has betrayed Allah, His Apostle and the believers! Let me cut off his neck!" The Prophet asked Hatib, "What made you do this?" Hatib said, "By Allah, I did not intend to give up my belief in Allah and His Apostle but I wanted to have some influence among the (Mecca) people so that through it, Allah might protect my family and property. There is none of your companions but has some of his relatives there through whom Allah protects his family and property." The Prophet (Peace and blessings be upon him) said, "He has spoken the truth; do no say to him but good." `Umar said, "He as betrayed Allah, His Apostle and the faithful believers. Let me cut off his neck!" The Prophet (Peace and blessings be upon him) said, "Is he not one of the Badr warriors? May be Allah looked at the Badr warriors and said, 'Do whatever you like, as I have granted Paradise to you, or said, 'I have forgiven you."' On this, tears came out of `Umar's eyes, and he said, "Allah and His Apostle know better." {Related by Bukhari}.
Al-Khattabi (May Allah have mercy on him) said, "This narration shows that there is a difference in the ruling of Sharia between one who commits a crime but has a valid and acceptable justification for what he did and one who commits a crime on purpose and for no valid reason."
In addition, Ibn Battal said, "If a Muslim unintentionally reveals a secret to the disbelievers and he is of noble character and has a valid interpretation for what he did, then it is permissible to pardon him as the Prophet (Peace and blessings be upon him) did with Hatib. In addition, it is worth pointing out that this act of forgiveness may be practiced by any of the Muslim leaders and it isn`t peculiar to the Prophet (Peace and blessings be upon him). "{Shareh Sahih Al-Bukhari, V.5:165}.And Allah the Almighty knows best.