I have done it, and when I was younger people have done it for me.
Sort of. I’d say that the conflict is one-sided, and mostly exists in the harasser’s mind. So introducing oneself into the situation can break whatever feedback loop that person is caught up in. In their mind, they model a simplistic problem and a resolution which they act out. Their fantasy gets interrupted by the unexpected, what wasn’t part of their model.
Another perspective is that besides instilling shame (which is certainly possible) is that it teaches by example better ways of interacting with people and solving problems.
Of course, awareness is key. But I am more likely to look for help from those around me than call the police. Because unfortunately they have earned a reputation for not handling racial/ethnic violence well. There is no way to know if they will de-escalate the harasser or agree that the victim appears guilty of existing while black, or some similar situation.
This might not teach the aggressor a deep moral framework, but it can be more positive and proactive. It causes them to re-think what they are doing, whereas confronting them with something like “Hey Jerkface, you don’t have any right to be a bigot to them!” will likely result in them reflexively doubling down, even if only internally.