If you carefully read the verses discussed, you can see that God only instructed Moses to take vengeance against the Midianites for the wrong they did to Israel.
Since the Midianites were also Hebrews like the Israelites the battle laws against the Canaanites didn't apply.
Moses wife's family were Kenites that is from Midian.
It is Moses who gets all bent out of shape about the women and children being left alive and then orders to kill them.
It was not a command of God that the children and mothers should be slaughtered.
God did allow this to happen, but Moses was not allowed into the promised land especially for taking matters into his own hands.
Jesus, when discussing about the resurrection, said that Moses is the one that allowed for polygamy and divorce etc. although this was not the arrangement of God from the beginning.