This brings up two questions: First, why מדין and not מואב? It was מואב that hired בלעם, and it was with בנות מואב that בני ישראל sinned! Second what happened to this command? We don’t see them going to war with מדין; the next thing is the census, then the laws of inheriting the land. It’s not for another 6 chapters that we get to the actual war, and then ה׳ needs to command it again:
The question of what happened to מואב is even stronger when we realize that בני ישראל were specifically commanded not to attack מואב, in very similar terms to the command to attack מדין:
Multiple reasons are given in the commentators:
There are two basic categories of these answers: either מואב's sin wasn’t as bad (either they were acting in self-defense, or what they actually did wasn’t as bad), or (Rashi’s second answer) מואב needed to be preserved because they still had the potential to redeem themselves.
As for the second question, why didn’t the war take place after the command, we have to look closely at the wording. There are two commands here, צרור and הכיתם. The first thing they need to do is צרור, make them enemies:
It takes a period of mental preparation to go to war with מדין. And the war itself was different from other wars:
And this war is clearly meant to be more spiritual, with the explicit requirement that the כהן and the כלי הקדש go with them. This was one war that the tribe of Levi had to participate in. The war with Midyan was a mental war, a war about a state of mind. It was similar to a previous war that involved a state of mind rather than just a physical battle:
But what is so bad about מדין? They are the people of יתרו, the in-laws of Moshe. Why treat them the same as עמלק?
The מדינים actively rejected יתרו and his family. There would be no more פירות coming from them:
Rashi explains how Midyan remembered Moshe’s days among them, but the Zohar puts a much more negative spin on their attitude:
What is it about Midyan that makes them such implacable foes of בני ישראל, that we need to see them as צוררים? Remember how we first met Midyan:
The Midyanites are slave traders. Note that the simplest reading of the Yosef story is that the Midyanites kidnapped him while the brothers were still deciding what to do. They don’t treat human beings as human beings; they are no different from animals. The Netziv above said עבודה זרה שלהם פעור, their god was Baal Peor, whose worship celebrated the most physical aspect of our lives. People are just bipedal animals. We don’t have to care about others or treat them as unique individuals.
And it is a seductive philosophy, which continued to haunt Israel:
The שם משמואל connects this aspect of מדין to the destruction of the בית המקדש itself:
And as we approach the three weeks, we have to realize that the cure for the גלות is to remove the קליפת מדין, to recognize others as human beings and individuals who have their own significance and therby remove the age-old stain of שנאת חנם.