The various principles (qawa’id) outlined by the classical jurists (fuqaha) are a result of extensive study of the injunctions (masa’il) of fiqh throughout the ages and eras. These principles did not just come about due to the personal ideas or experiences of the fuqaha or by coincidence for that matter. Rather, these principles can be found as early as the era of the Companions and their followers (tabi’in, Allah be pleased with them all).
We can find certain principles (qawa’id) directly in the Qur’an and Sunnah itself. For example, Allah Most High says:
“Hold to forgiveness; command what is right; but turn away from the ignorant.” (Surah al-A’raf, 1999)
The above verse consists of three sentences all of which are in fact principles that form a basis for other injunctions of Shariah. For instance, in the command “Hold to forgiveness” rulings such as: having good ties with those that break them, forgiving those who do wrong and generally being polite, are all included.
In the statement “Turn away from the ignorant” there is encouragement to acquire knowledge, not engaging in fruitless arguments and staying away from oppressors, etc…
Similarly, there are many such principles in the Hadith collections that are narrated from our beloved Messenger of Allah (Allah bless him & give him peace), especially in those Ahadith that are regarded as ‘pearls of wisdom’.
a) “Every intoxicant is unlawful” (Sahih Muslim)
b) “Any lending arrangement which results in some benefits to the lender is Riba” (Sunan al-Bayhaqi).
c) “Every matter newly begun is innovation and every innovation is misguidance” (Sunan Abu Dawud).
d) “Any condition that is not in the book of Allah is void” (Sahih al-Bukhari).
e) “Every good action is charity” (Sahih al-Bukhari)
f) “Proof is to be provided by the plaintiff and the defendant has to swear the oath” (Sunan Tirmidhi)
g) “Delay (in the repayment of debt) by a wealthy person is oppression” (Sahih al-Bukhari).
h) “There is no obedience to any creation in which there is disobedience to the creator” (Musnad Ahmad).
So the general principles in the Sunnah are numerous, and they, along with the principles in the Qur’an, are the original basis on which the Fuqaha formed the Qawa’id.
The Fuqaha also based their own Qawa’id (that were not explicitly mentioned in the Qur’an and Sunnah) on the Qur’an and Sunnah. They formed many such principles, which have been compiled in many books. Scholars such as Ibn Nujaym in his al-Ashbah wa al-Naza’ir, Abu Zaid Dabusi in his Ta’sis al-Nazar, Imam al-Karkhi in his al-Usul and al-Atasi in the al-Majallah, have all gathered various principles in the Hanafi Madhhab that related to various aspects of Shariah.
Also, al-Furuq by Imam al-Qarafi (Maliki Madhhab), Qawa’id al-Ahkam fi Masalih al-Anam by Izzuddin ibn Abdus salam (Shafi’i Madhhab) and al-Qawa’id by Ibn Rajab al-Hanbali (Hanbali Madhhab) are all considered to be great works and fundamentals of this science.
Coming to the principle regarding which you have asked that states: “If one is overcome by two evils, one should choose the lesser of the two.”
This general principle has been mentioned in almost all of the books written in this science. It is a principle that is based on the concept of trying to avoid sin and harm as much as possible. It has been derived from the general guidelines found in the Qur’an and Sunnah.
Allah Most High says:
“So fear Allah as much as you can.” (al-Taghabun, 16).
Similarly, Allah Most High says:
“They ask you concerning fighting in the prohibited month. Say: Fighting therein is a grave (offence), but graver is it in the sight of Allah to prevent access to the path of Allah, to deny Him, to prevent access to the sacred Mosque and drive out its members. Tumult and oppression are worse than killing.” (Surah al-Baqarah, 217)
In this verse, Allah Most High mentions that the Pagans of Makkah accused the Muslims of breaching the custom by coming out to fight in the prohibited month. However, despite fighting in the prohibited month being a grave offence, the Muslims were forced to choose the lesser of the two evils, as not fighting would leave the enemies continuing their persecution of the Muslims. Therefore, the Muslims were driven to fight in self defence during that period against their own feelings.
In the fifth year of Hijra, the Messenger of Allah (Allah bless him and give him peace) agreed to a truce with the polytheists of Makkah known as the Sulh al-Hudaybiyya. The Messenger of Allah (Allah bless him & give him peace) compromised with them on many accounts and relinquished the rights of the Muslims. It was agreed that if anyone from the non-believers came to Madina, the Muslims must send them back, whereas in the reverse situation, they would not be returned. The Messenger of Allah (Allah bless him & give him peace) agreed to this keeping in mind the greater evil, which was the expected torture of those believers that remained in Makkah, and also to prevent instant bloodshed. This was looking into the long term gain.
Another well known incident is of a villager who had newly accepted Islam. This villager, not knowing the etiquettes of the Masjid, began to urinate in it. The Messenger of Allah (Allah bless him & give him peace) did not stop him instantly, rather he let him finish first and then explained to him in a polite manner that, it is inappropriate to urinate in the house of Allah (Sahih Muslim).
Here, the Messenger of Allah (Allah bless him & give him peace) tolerated the lesser evil by letting him finish urinating and prevented two greater evils that were:
1) Stopping him would cause him to run, thus the entire Masjid would become polluted.
2) Rebuking may drive him away from Islam and cause hatred in his heart. (See: The major commentaries of Hadith collections).
Some examples in matters of Fiqh where this principle is used (Taken from Ibn Nujaym’s al-Ashbah):
a) In one was wounded in a way that if he performed prostration (sajda) in prayer, blood would come out and flow. However, if prostration was avoided, it would not come out.
In this situation, he will be ordered to offer his Salat sitting down with gestures, as leaving the Sajda is a lesser evil than offering the prayer in the state of ritual impurity. Leaving the Sajda is permissible in optional prayers unconditionally, whereas Salat can never be offered in the state of ritual impurity.
b) An old and ill person is incapable of reciting (in prayer) whilst standing, but is able to do so in the posture of sitting. The ruling in such a case will be that he must offer his Salat sitting down and make the recitation, as offering Salat whilst sitting is a less of an evil than omitting the recitation.
c) If one is forced to eat by necessity either dead meat or the wealth of another person, then he should eat the dead and unlawful meat, as eating dead meat is lesser of an evil from the two.
And Allah Knows Best