A mekhitza is a dividing wall or barrier that is used to separate men and women. It could be simply a separate room, a curtain, or anything else that serves as a barrier. Many synagogues do not have a mekhitza; it is used primary by Orthodox Jews during worship. The reason given for mekhitza is that it would supposedly help men focus on their prayers rather than on women. It is also said that the mekhitza was made as a response to the surrounding non-Jewish communities who included sexual activities in their rituals which Judaism wanted to distance itself from, preventing any confusion by separating women and men during worship altogether ("The Synagogue: The Mekhitza").
The closest thing in the Torah to a command for separation between genders that I have found is the statement, "So Moses went down from the mountain to the people and sanctified the people, and they washed their clothes. And he said to the people, 'Be ready for the third day; do not come near your wives'" (Exodus 19:14-15). In context, the Lord was going to have a special meeting with Israel, and being clean -- avoiding sexual relations and/or distractions -- seemed to be part of the requirement for preparation in this case.
Sex is not bad. Just like eating is not bad, but fasting (abstaining from food) was done in the Bible so that people could prioritize the eternal over temporal. "Proclaim a holy fast, call for a solemn assembly, gather the leaders and all who live in the land to the house of Adonai your God, and cry out to Adonai" (Joel 1:14). Likewise, sex is fine in itself (in the context of marriage), but refraining can help people focus on more important things. "Do not deprive each other of sexual relations, unless you both agree to refrain from sexual intimacy for a limited time so you can give yourselves more completely to prayer. Afterward, you should come together again so that Satan won't be able to tempt you because of your lack of self-control" (1 Corinthians 7:5).
However, that verse doesn't promote the extreme view that one cannot see women while worshiping God. The Bible says, "Don't let your heart lust after her beauty or allow her glance to captivate you" (Proverbs 6:25). Lust is something one must take personal ownership for, and one cannot blame a women's presence for lust any more than Adam could blame Eve for his own behavior of choosing to eat the forbidden fruit. God did not ask man to remove the forbidden fruit from the garden; God asked man to be righteous despite the presence of the forbidden fruit. The problem wasn't the tree; it was the coveting and theft inside the heart. Likewise, it is not a woman's presence that should be removed during worship; it is the impurity in the heart that needs to be removed, regardless of how a woman looks. It is a sinful heart that makes doing wrong tempting, not your surroundings.
We should note that "So God created humankind in his own image; in the image of God, he created him: male and female he created them" (Genesis 1:27). There is no need to hide half of God's image because God's image is in both genders serving the Lord. It is not a sin to want some privacy of course, or even spend some time with only your own gender on occasion if your motives are fine. And while no one should be lustful during worship, seeing the opposite gender is not the problem or something one can blame lust on. No law says women and men cannot see each other during worship, so the mekhitza is not necessary, a new heart is. "Create in me a pure heart, O God, and renew a steadfast spirit within me" (Psalm 51:10).
Reference:
"The Synagogue: The Mekhitza," Jewish Virtual Library.