Why did God order the Israelites to kill all the males in a land after capturing it but spare the females?
In fact it was an (ancient?) common war usage because males are usually consider more dangerous. Jugurtha, king of Numidia, in 112 BC killed all the adult males of Cirta. Thucydides reports an interesting debate about the fate of the Mytileneans during the Peloponnesian War there were two different position: Kleon wanted to kill all the Mythilenens adult males while Diodotos only those most responsable of the revolt in question. Killing the males means avoid possible rebellions, men are stronger and in all the patriarchal societies are the base of the political and militar affairs. So kill all the males of a comunity means for the most cases destroy the identity of the comunity. While women can be kept as slaves (maybe concubines, but YHWH forbid to have sons from non-ebraic women Deut 7:3) depending on the needs. In fact there are more drastic solutions of killing the male children too, you can find it in Numbers 31:15-18 in these verses is written to kill even non-virgin women this can be hardly explained rationally maybe was supposed married women were less incline to be subdued. The most drastic solution is of course to kill everyone (Deuteronomy 20:16).
You might be helped with my answer to the following question: Why Moses ordered to keep virgins alive but kill all non-virgins and males in Numbers 31:17-18?
In some ways your question is similar to the one I just cited.
First, God commanded Israel to annihilate completely the inhabitants of Palestine/Canaan (specifically the "tribes" and "nations" therein) because of their abominations and defilements. In Genesis 15 we read the following:
The word Amorite, as it is used here is a synecdoche in which the Amorite nation (or peoples) stands for all the nations Israel was to dispossess in their conquest of Canaan. Depending on which Old Testament book you consult, the number of nations Israel was ordered to dispossess ranges from four to ten (see, for example, Genesis 15:19-21; Exodus 3:10; 13:5; 23:23; 33:2; Deuteronomy 20:17,18; Joshua 3:10). What they all had in common besides their rampant immorality was their occupation of the land God promised to Abraham hundreds of years before Joshua came on the scene.
In the interim between Abraham and Joshua, the sins of the "Amorite" became worse and worse, to the point where God's patience with them came to an end because of their wickedness. In other words, when nations reach a certain level of wickedness, God is forced to intervene with severe punishment. As the New Testament tells us, God is not willing--nor does in take delight in--the death of anyone, but He desires that all people everywhere repent (see 2 Peter 3:9). When a people is beyond redemption, God's mercy gives way to His justice.
In the chapter from which you quote verses 13 and 14, we also read the following commandments from Jehovah:
Moreover, further down in the chapter we read this:
Clearly, only the nations that were "close by" were marked by God for annihilation; as for the "cities that are very far from" Israel which were "not of the cities of . . . [the] nations nearby," Israel was given permission either to make peace with them and then make them slaves, or if they refused to make peace with Israel, to kill only the men and spare the women and children (see vs.18).
The clear inference, then, is that the nations far away were not as wicked as the nations that were close by. Seeing this, God spared the women and children.
In conclusion, we needn't dwell on the baseness of the sins of the "Amorite." Frankly, the sins are almost too revolting even to enumerate. When any people group becomes so reprobate in their behavior, God resorts to drastic measures to prevent the cancer of their sin from spreading to neighboring nations. A biblical expression for a nation's extreme wickedness is found in Leviticus 18:25 (NIV):
What a graphic expression in describing the utter depravity of a nation: its people become so wicked that they sicken the land they inhabit.
Israel, on the other hand, was first to purge the land of this wickedness, and second, to set an example of godliness, righteousness, and justice to the nations surrounding them, so that these nations who would not only fear the "one true God" of Israel, but would be attracted to Israel's God and seek Him out. God was not just Israel's God, but God over all the earth. As 2 Chronicles tells us,