This is the whole chapter so it does provide some context. If you go way back to the covenant God made with Abraham, He promised to protect His people against thier enemies and allows killing in times of war. Just because God allowed the defeated to be handed over to the Jews, is not necessarily unjust or bad. The Jews had the Law and they were charged to obey it. No one outside of the covernant community has the Law nor were they charged by God to keep it. This expalins why there was a high level of barbarism. The scripture you quote shows no injustice on the part of God or His people.
Deu 20:1 When you go out to battle against your enemies and see horses and chariots, a people more than you, do not be afraid of them. For Jehovah your God is with you, who brought you up out of the land of Egypt.
Deu 20:2 And it shall be, when you come near to the battle, the priest shall go up and speak to the people,
Deu 20:3 and shall say to them, Hear, O, Israel, today you go up to battle against your enemies. Do not let your hearts faint, do not fear, and do not tremble, neither be terrified before their faces.
Deu 20:4 For Jehovah your God is He who goes with you to fight for you against your enemies, to save you.
Deu 20:5 And the officers shall speak to the people saying, Who is the man that has built a new house and has not dedicated it? Let him go and return to his house, lest he die in the battle and another man dedicate it.
Deu 20:6 And who is the man that has planted a vineyard and has not used its fruits? Let him go and return to his house, lest he die in the battle and another man use its fruits.
Deu 20:7 And who is the man that has become engaged to a wife and has not taken her? Let him go and return to his house, lest he die in the battle and another man take her.
Deu 20:8 And the officers shall speak further to the people, and they shall say, Who is the man that is fearful and faint-hearted? Let him go and return to his house, lest his brothers' heart faint as well as his heart.
Deu 20:9 And it shall be, when the officers have made an end of speaking to the people, they shall make captains of the armies to lead the people.
Deu 20:10 When you come near a city to fight against it, then shout peace to it.
Deu 20:11 And it shall be, if it makes the answer of peace and opens to you, then all the people found in it shall be forced laborers to you, and they shall serve you.
Deu 20:12 But if it will make no peace with you, but will make war against you, then you shall besiege it.
Deu 20:13 And when Jehovah your God has delivered it into your hands, you shall strike every male of it with the edge of the sword.
Deu 20:14 But the women, and the little ones, and the cattle, and all that is in the city, all the spoil of it, you shall take to yourself. And you shall eat the spoil of your enemies, which Jehovah your God has given you.
Deu 20:15 So you shall do to all the cities which are very far off from you, which are not of the cities of these nations.
Deu 20:16 But of the cities of these people, which Jehovah your God gives you for an inheritance, you shall save alive nothing that breathes.
Deu 20:17 But you shall utterly destroy them: the Hittites, and the Amorites, the Canaanites, and the Perizzites, the Hivites and the Jebusites; as Jehovah your God has commanded you,
Deu 20:18 so that they may not teach you to do according to all their abominations which they have done to their gods. So you would sin against Jehovah your God.
Deu 20:19 When you shall besiege a city a long time in making war against it to take it, you shall not destroy its trees by forcing an axe against them. For you may eat of them, and you shall not cut them down. For is the tree of the field a man that it should go before you to lay siege?
Deu 20:20 Only the trees which you know that they are not trees for food, you shall destroy and cut them down. And you shall build bulwarks against the city that makes war with you, until it is subdued.