Imam al-Shafi'i (may Allah have mercy on him) said: "The imam has a choice concerning them (prisoners of war): if the idolaters do not accept Islam and the People of the Book do not pay the jizyah, he may kill them; or he may release them as a favour (without compensation); or he may ransom them, whether for wealth he takes from them or for Muslim captives released in exchange for them; or he may enslave them. If he enslaves them or takes wealth from them, its ruling is that of the spoils of war: its one-fifth (khumus) is taken out and the remaining four fifths belong to those entitled to the spoils. If someone says: You have given a single ruling regarding wealth, children and women, and different rulings regarding men; why is that? It will be said (to him): the Messenger of Allah (peace and blessings be upon him) overcame Banu Qurayzah and Khaybar and divided their immovable property, that is, their lands and date-palm orchards, as wealth is divided; and he (peace and blessings be upon him) took captive the children and women of Banu al-Mustaliq and Hawazin and divided them too as wealth is divided."
The Shaykh (Imam al-Bayhaqi) (may Allah have mercy on him) said: "As for what he said about Banu Qurayzah, it is in the (narration) that follows."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب السير / Q18021