Zechariah - Chapter 12
Moshiach ben Yosef's Mechitza
G-d finished His words to Zechariah about the fate of Israel. Thus says G-d (Who created the universe and mankind): I am mixing for Jerusalem a cup that will weaken those who attack them. Jerusalem will become a burden - it's simply too much trouble to attack them, so they'll be left alone. Those who attack, both horse and rider, will be confounded. Jerusalem will be like a fiery oven and they will consume their attackers. Rebuilt Jerusalem will be on the site of the original.
G-d will save the cities of Judah before He does Jerusalem, so that Jerusalem won't think that salvation is solely in their merit. On that day (presumably the war of Gog and Magog), G-d will protect Jerusalem. The weakest among them will be like David, a mighty warrior in battle. The house of David, including Moshiach (the Messiah) will be like angels of G-d. G-d will pour a spirit of grace over Jerusalem. They will turn to G-d because of those who were slain in battle and they will mourn as one would over a firstborn son. Everyone will mourn, the men and women in separate groups.
The Talmud in Succah (52a) applies this prophecy to the Moshiach ben Yosef, the Josephic (rather than Davidic) messiah. The fact that the men and women mourn separately is a source of the practice of separating the genders socially or in various religious contexts. If they separated for propriety's sake in a context that would not encourage frivolity (while mourning), how much more so should we take appropriate precautions in situations that would lend themselves to lightheadedness (ibid, 51b)!