When the Jews first returned to Israel, they had to uproot the Canaanite nations that had been living there during their exile. These nations were thoroughly steeped in idolatry, which is anathema to the land of Israel. The Canaanite nations had three choices when it came to Israel’s conquest of the land: they could evacuate in peace, they could agree to accept Israel’s rule, including observing the seven universal (Noachide) laws, or they could fight. Agreeing to live in peace in Israel while worshipping idols was not an option. (In the Book of Joshua, chapter 9, the Gibeonites came up with a clever alternative: they pretended to be foreigners from another land and forged a treaty under false pretenses. Even though they misrepresented themselves, Joshua insisted that the agreement be honored.)
The reason underlying this mitzvah is the complete abhorrence of idolatry. Idol worship is always unacceptable, but especially so in Israel, and these nations were especially prolific idolators. Therefore, the rules regarding this particular scenario are more stringent than those dealing with other idolators and/or other places. (We see this from the fact that Joshua was able to make a peace treaty with the Gibeonites when he thought that they were from a foreign land.) It’s nothing personal; if they abandon their idolatry, we have no beef with them (see Talmud Gittin 45a).
The prohibition against making a pact with the Canaanite nations – surprise! – is in effect at all times and places for both men and women. You will probably never meet a Hittite or a Jebusite, but you’ll also never meet an Amalekite and it is commonly understood that the mitzvah to eradicate Amalek applies for all generations. We will discuss this at greater length IY”H when we come to Mitzvah #425, the positive commandment to eradicate the idolatrous Canaanite nations.
This mitzvah is discussed in the Talmudic tractate of Sanhedrin and is codified in the Mishneh Torah in the tenth chapter of Hilchos Avodas Kochavim. It is #48 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos. (The Chofetz Chaim does not list this mitzvah independently in his Sefer HaMitzvos HaKatzar.)