The pitcher walks 3 batters to start the inning. Infield in, the next batter hits it to right field and the fielder makes and error and all 3 runners on score. Man on second, no outs the next batter hits a home run. 5-0 now and then the pitcher gets 3 straight outs. How many earned runs for the pitcher?
9.16 Earned Runs and Runs Allowed
An earned run is a run for which a pitcher is held accountable. In determining earned runs, the Official Scorer shall reconstruct the inning without the errors (which exclude catcher’s interference) and passed balls, giving the benefit of the doubt always to the pitcher in determining which bases would have been reached by runners had there been errorless play.
So you replay the inning as if the error had not occurred and determine which would have scored and which would not.
There's lots of ways a right fielder might make a play, but in none of them would I assume a second out is possible. The runner on third will either remain there or will score on the fly ball if the catch is deep.
Without the error, here's one way the inning could have played out:
B4: F9 (1 out)
B5: HR (4 runs)
B6: out (2 out)
B7: out (3 out)
In this scenario, B4's run is unearned, the other 4 are earned.
A game that played similar to this in MLB is the August 5, 2023 meeting between the Braves and the Cubs.
In the bottom of the first, 2 runs score (and B4 reaches) on an error at first base. But although they came in on the error, these runners "would have" scored due to a home run by B5.
2 runs in that inning are unearned: B4 (who reached on the error), and B7 (who homered after 2 outs). The other 3 runs were all charged to the pitcher.
One, the batter that hit the home run.
The three that walked scored on an error, that being the dropped catch by the outfielder.* That batter reached base on an error. So all of those are unearned, as they occurred with the help of an error.
An earned run is any run that scores against a pitcher without the benefit of an error or a passed ball.
*This answer assumes that was the error. If you mean it was a hit- say a single- that the fielder misplayed, the analysis changes.