Washington has won 15 of its last 16 home games and taken nine series in a row at RFK Stadium. The NL East leaders set a franchise record with 20 wins in June.
"That's a tremendous year, or month, I'm sorry," manager Frank Robinson said. "After the last three years, it seems like a year. That's a tremendous month, and the players deserve an awful lot of credit for the way they have performed and the way they have handled things. They just keep going out and doing the job."
Cordero earned his 15th save in June to tie a major-league record set by Lee Smith in 1993 and matched by John Wetteland in 1996. Cordero wiggled out of a second-and-third, no-outs jam in the ninth inning for his 25th straight save and major league-leading 28th overall. He retired Ryan Doumit on a routine fly with the bases loaded for the final out.
"I'm kind of getting used to it because I've been thrown into it so many times," Cordero said. "I was getting a little worried when they were at second and third with no outs, but I really have no idea how I do it."
Pirates manager Lloyd McClendon was ejected in the second inning for arguing with plate umpire Chris Guccione. Pittsburgh lost for the 13th time in 17 games.
Kip Wells (5-8) struggled with his command in a brief outing, walking four batters and allowing four runs in two innings. Wells has lost four straight starts, allowing 20 runs in 16 2/3 innings.
Castilla hit a solo homer into the mezzanine level in left field and a two-run single in helping the Nationals build a 7-4 lead.
"Every time you hit a home run it's a great feeling, especially when you help the team win a ballgame," Castilla said. "I hit it pretty good, but I didn't think it was going to go way up there."
Pittsburgh scored once in the eighth on consecutive singles by Jason Bay, Daryle Ward and Doumit. Ward was later thrown out at the plate on a grounder and pinch-hitter Matt Lawton popped out to end the inning.
Down by two runs, the Pirates quickly threatened in the ninth with a single and double. Cordero retired Rob Mackowiak on a shallow fly ball and struck out Bay before intentionally walking Ward to load the bases. Doumit flied to right field to end it.
"We were a base hit away from tying the game, but we just couldn't get it done," Wells said. "These are the games that have eluded us. That's what we have to do if we want to compete in the National League."
Loaiza struck out six, including five on called strikes, and walked none. He gave up four runs and five hits, and pitched into the sixth.
Brad Wilkerson led off the Nationals' first with a single, moved up on a walk to Jose Guillen and scored with two outs on a bloop single by Marlon Byrd. After Wells walked the bases loaded in the second, Guillen hit an RBI single and Castilla's single made it 4-0.
Reliever Ian Snell replaced Wells and gave up Schneider's fifth home run of the season, a drive that made it 6-0 in the third.
Pittsburgh scored twice in the fifth, and Ward singled home two more runs in the sixth. Castilla homered in the seventh.
- Nationals SS Cristian Guzman left in the ninth, an inning after straining his left hamstring running out a bunt. Robinson said Guzman will travel to Chicago and may be available to play at the end of the series.
- McClendon was ejected for the fourth time this season.
- Nationals 1B Wil Cordero doubled in the fifth inning for his second hit of the season, ending an 0-for-17 slump. He also walked in the third inning to snap a streak of five straight strikeouts.