Philadelphia trailed 7-1 after four innings but rallied for six runs on eight hits from the sixth through the eighth inning to tie the game.
But in the bottom of the eighth, reliever Connor Brogdon (2-1) surrendered a two-out, go-ahead single to Nats right fielder Lane Thomas.
"I was happy with the offense,” said Phillies manager Rob Thomson. “They kept grinding, they came back. We swung the bats a lot better tonight. We had a couple of poor routes in the outfield that cost us, cost [Zack] Wheeler some pitches. But I was happy that they came back and they kept fighting."
Castellanos ignited the offense with a pair of home runs and delivered a bases-loaded two-run single in the seventh to fuel the comeback.
The right fielder connected on a season-high four hits with a season-high five RBIs, finishing with a single, a double, two homers, two runs scored and a stolen base.
"Consistently, I have kind of been finding my stride and settling in,” Castellanos said. “Being able to repeat the same things every day, so finding consistency in that and seeing the ball a little bit better."
But the bottom line is both teams are now 25-32, tied for last place in the National League East. The defending NL champions have lost five in a row. It’s the fourth time this season the Phillies have gone on a losing streak of four or more.
"We need to be more consistent,” Bryce Harper said. “That's it. It's not good to go through streaks like that when you are trying to be a winning ballclub. [We] just need to be better."
Harper went 0-for-4 with two strikeouts and a walk against his former team. The Phillies slugger struck out to begin the ninth and now has just two hits in his past 21 at-bats.
Castellanos, who also hit two homers April 22 vs. Colorado, recorded his 11th career multihomer game.
"There's definitely a lot of positives. As a group, [we’re] showing some fight,” Castellanos said. “It would've been really, really easy to lay down and allow the way the game started to be the way that it finished. Obviously, we didn't come through, and we walk away with a loss. It's not ideal. It's frustrating. But it is what it is."
Castellanos crushed a solo homer off Nationals starter Josiah Gray to lead off the fourth inning. In the sixth, he connected with a two-run blast off Gray, cutting the Nats’ lead to 7-3.
"He's aggressive,” said Gray. “He's aggressive to everything. You don't make $100 million in your career and just hit singles. He drives the ball. And I've faced him for two years now, and he's got me a few times, I've gotten him a few times, so it's always a battle with him."
Wheeler lasted 3 2/3 innings, expending 90 pitches (58 strikes) and surrendering a season-worst seven runs one start after tossing eight shutout innings at Atlanta May 27.
Washington went 4-for-4 with runners in scoring position to begin against Wheeler. Jeimer Candelario did most of the damage with two doubles and three RBIs. It was Wheeler’s first loss in his past five starts against the Nats.
"I put us down in a big hole, and guys never quit,” Wheeler said. “[We] got some big hits, and guys stayed locked in. That's what good teams do, and I know we are a good team. We just [have] been playing a little inconsistent. It starts with the starting pitching. [We’ve] got to keep the runs off the board and keep momentum on our side."