Giving a Covenant of Security to Non-Muslims

Is it permissible for the ruler to give the non-Muslims a covenant of security to be under the protection of the Muslims, though they came to our countries to kill other Muslims? May Allah reward you.

All praise is due to Allah alone. Peace and blessings be upon the Messenger of Allah. This question needs delineation:
First, if we are to be sincere to the Muslims, we should lay emphasis on some points: the ruler is authorized to give security pledges and covenants to all or some of the non-muslims, because he is responsible for considering any benefits or harm, facilitating the first and keeping away the latter. This point is beyond any controversy. In this regard one can refer to books such as al-Mughny by Ibn Qudamah, the explanation of the Quran by al-Qurtuby, and others.
It is not a condition that the one who rules over the Muslims be observant of the night Prayer or voluntary fasting. It is enough that he gains power through people’s swearing alliance and obedience to him (bay`ah), being the crown prince (wilayat al-`ahd), or taking power by force. This is the juristic position of ahl al-Sunnah (those who adhere to the Sunnah). Such a ruler can give a security pledge without any time limit based on his consideration of the interests of the public. This is the first point I wanted to make clear.

The second point is that when the ruler gives a pledge of security, we should assume that he intends to achieve some benefit; because people should be considered to be basically peaceful and honest, not aggressive. Thus, we should believe that they made any pledge for some benefit that the people may have been unaware of; namely, it could have been unavailable or unclear to the people, either to achieve a benefit or to avoid some harm. So let us construe their deeds this way.
The third point is that if we presume the truthfulness of the questioner’s words who said that they (the unbelievers) had the intention to kill the Muslims, such a covenant would not be permissible. But at the same time this does not give permission for the questioner to rebel against the ruler and launch a war against both the Muslims and the non-Muslims.
Therefore, we ask: What is the result of this covenant of security? Is it to prevent killing and fighting? We advice the questioner to be occupied only about his own concerns and to busy himself with worshiping Almighty Allah and amending his religious and worldly affairs, and not to drive himself or others into a whirlwind that will bring nothing but the destruction of his religious and worldly affairs, and the loss of this world and the Hereafter.
We give this sincere advice for the sake of Almighty Allah who said, “So fear Allah as much as you can” And the Prophet (peace and blessings be upon him) said, “Whoever among you sees an evil practice ought to change it with his hand. If he cannot, let it be with his tongue….” [Reported by Muslim (49)] What does “If he cannot” mean? It means: If changing the evil with your hand will lead to disastrous consequences, change it with your tongue.
Moreover, if your tongue will lead to corruption and enormous losses, you may change it with your heart, particularly with regard to matters that you cannot be fully aware of. You said that they had the intention to kill Muslims. Who told you that they had this intention?
We advice our young men, as well as all the Muslims, to be wise and not to become hardheaded. They should not entertain ill thoughts or become engaged in a series of violence and a whirlwind of destruction that destroys the homes of the Muslims’ themselves and may not cause any great harm to the non-muslims. For Muslims will then kill one another and will kill those under the pledge of security whose killing Allah has prohibited and whom Allah has protected their blood from the Muslims. This is our advice.
Almighty Allah knows best