I know that we are not supposed to pray in front of a married woman that doesn’t cover her hair, but sometimes, like at a sheva berachot, one needs to say birkas hamazon in front of a woman with uncovered hair, or at a beit aveil, where one has to pray in similar circumstances. Can I still go to these places, if I know that this problem is going to come up, or is better to try to avoid this?
If there is some need to go to such places, such as to show proper honor to the family involved, it is permitted to go there.
You should try to turn away from the lady with uncovered hair, or to close your eyes.
Sources: With regard to uncovered hair, concerning which many women are (unfortunately) not particular, a number of autohrities are lenient concerning reciting blessings and prayers (such authorities include Aruch Hashulchan, Ben Ish Chai, Or le-Zion, and others). However, Mishnah Berurah (75), and other poskim, do not suggest such a leniency, and therefore one should act stringently, and try to turn oneself away from uncovered hair, or close one’s eyes. See Shulchan Aruch, Orach Chaim 75:2; Mishnah Berurah 75:1, 5, 29; Nishmas Adam 4:1. Because making a blessing in front of uncovered hair is only a rabbinic prohibition, Mishnah Berurah rules (based on Nishmas Adam) that it is sufficient to close one’s eyes, and there is no need to actually turn oneself away.