Does Halacha allow Jews to commit physical or psychological torture against their enemies when necessary (e.g. in a time of war, to get vital information from them, etc.) and to what extent is it allowed?
The earliest source I found concerning physical torture is in Judges 1:6-7 (Book of Shoftim), where it says וַיָּנָס אֲדֹנִי בֶזֶק וַיִּרְדְּפוּ אַחֲרָיו וַיֹּאחֲזוּ אֹתוֹ וַיְקַצְּצוּ אֶת בְּהֹנוֹת יָדָיו וְרַגְלָיו. וַיֹּאמֶר אֲדֹנִי בֶזֶק שִׁבְעִים מְלָכִים בְּהֹנוֹת יְדֵיהֶם וְרַגְלֵיהֶם מְקֻצָּצִים הָיוּ מְלַקְּטִים תַּחַת שֻׁלְחָנִי כַּאֲשֶׁר עָשִֹיתִי כֵּן שִׁלַּם לִי אֱלֹהִים וַיְבִיאֻהוּ יְרוּשָׁלַםִ וַיָּמָת שָׁם: Ralbag explains this was done to intimidate the Canannate rulers and also to punish Adoni-bezek measure for measure for what he did to his own victims. Retracting my previous assumption, I noticed that Ralbag implies that this was not commanded by God, but it was done by His will anyway. Malbim says that God put in their minds to do this to him.
I haven't seen a source for this, but it may be that God directly commanded them in a prophecy, through the Urim V'tumim, or that the leaders were divinely inspired to do this retribution (Malbim implies this last option). I look at it this way: First of all, this man was as good as dead in God's eyes because he was from the 7 nations. Also, the Jews repaid him measure for measure, without putting him through extra torture than necessary to accomplish their goals. They even let him live after he confessed his sins and he died in Jerusalem as the verse states (It may be though, that they let him live because that would show their control over Adoni-Bezek, and this privilege is not given to the average individual of the 7 nations even if he confesses).
This case is the only case of the sort I can find, so it seems that this measure is only allowed when: 1- the person is going to be killed anyway, 2- it supports the cause of an obligatory war (milchemet mitzvah), 3- It is done exactly measure for measure according to one's deeds, 4- It seems to require some form of divine sanction (but this point is not clear).
The story of Yom Har Gerizim comes to mind. The 21st of Kislev was a holiday mentioned in Megilas Taanis and explained in Yoma 69a. Short version the Kusim slandered the Jews in an attempt to have the Beis Hamikdosh destroyed. Alexander the great famously meets Shimon Hatzadik, and hands the Kusim over to him to be done as seen fit. Their heels are punctured so as to be tied to the tails of horses and they are dragged to Har Gerizim which is subsequently razed and used for planting, as mida kineged mida for their plans to have this done to the Beis Hamikdosh.