He did it to train the descendants of Israel, the ones who had no battle experience, in the art of war.
what display of your redemptive power, lord! even the fruit of disobedience still gets to be used for your mighty work in the hearts and lives of those you call your own. thank you lord that your grace empowers us to turn back to you when we stray and be secure that you hold us in your hands no matter what. thank you lord that this world has got nothing on you, and when we give you our heart you will make sure that we get to be more and more like you and use all things no matter what to mould our character and let us be who you want us to be - the perfection of your plan, the fulfillment of your original design - no matter how far our past may have been from you. praise you, praise your lord for everything.