Taking help from the Mushrikeen in wars

Taking help from the Mushrikeen in the war.

an Nawawi mentioned the chapter in Sahih Muslim.
باب كراهة الاستعانة في الغزو بكافر إلا لحاجة أو كونه حسن الرأي في المسلمين
“Chapter: It is disliked to seek the help of a disbeliever in wars except in cases of necessity, or if he thinks well of the Muslims.”

And the hadith of Sahih Muslim states that the Prophet peace be upon him said to a Mushrik:

“Go back, I will not seek help from a Mushrik (polytheist)” (Until he accepted Islam and then only He took his help). [Sahih Muslim 1817]

an-Nawawi commented:
قوله صلى الله عليه وسلم : ( فارجع فلن أستعين بمشرك ) وقد جاء في الحديث الآخر : ( أن النبي صلى الله عليه وسلم استعان بصفوان بن أمية قبل إسلامه ) فأخذ طائفة من العلماء بالحديث الأول على إطلاقه ، وقال الشافعي وآخرون : إن كان الكافر حسن الرأي في المسلمين ، ودعت الحاجة إلى الاستعانة به استعين به ، وإلا فيكره ، وحمل الحديثين على هذين الحالين

The saying of the Prophet peace be upon him “”Go back, I will not seek help from a Mushrik”” It is mentioned in other hadith that “The Prophet peace be upon him took help from Safwan ibn Umaiyah before his Islam(i.e. when he was a Mushrik”. A group of scholars take the first hadith ala Itlaaquhu,

ash-Shafiee and others said: If a Kafir thinks well of the Muslims and it is necessity to take his help then his help will be taken otherwise it is disliked.

Both of the ahadith will be taken according to their cases.
[Shah an-Nawawi vol 12, Kitab al Jihad]