When the first pitcher leaves, he's given up 1 earned run. Since the guy who ROE erased himself, the rest of the inning is basically like the error didn't happen. Everything was earned after that.
How did they score 5 runs without someone scoring who was put on by the 2nd pitcher? The first pitcher only faced 5 guys, and one got CS.
Disclaimer: not a scoring expert.