The grand slam was the second of Castro's career and the Astros' fifth of the season, but their first at home.
"I've been feeling pretty good and hitting the ball, just not getting any luck, so this one was nice to have, especially at this point in the year," Castro said. "I feel like I'm right where I want to be and feel good, but the results haven't been there. I've been trying to do the same stuff, and the results will eventually come."
The Astros improved to 9-4 this season against the Rangers, meaning they need to win just once more time in the final six games of the Lone Star Series to win the Silver Boot for the first time since 2006. The Rangers were 17-2 against the Astros last season.
The win was the 57th for the Astros, their most in a season since 2010.
"The Texas Rangers handed it to us last year, and a man to a man, we all came out with the thought process this year that we want to reverse our fortunes against them, and we've played some of our best baseball against them this year," manager Bo Porter said.
Starter Collin McHugh (7-9) pitched well, holding the Rangers to eight hits, two runs and no walks in seven innings to win his third consecutive decision. He's 3-0 with a 1.91 ERA in six August starts, allowing only eight earned runs in 37 2/3 innings.
"It was one of those nights [when] I feel like I could have gone either way the whole night, any inning," McHugh said. "It's a credit to Castro for getting a good game plan in place and easing me through those first three or four innings. I feel like we were finally starting to find a groove a little bit in the fifth, sixth, seventh, and so it made it a little bit easier."
Trailing, 2-0, in the fifth, the Astros rallied when Jose Altuve singled with one out against Rangers starter Nick Tepesch (4-9), who was pulled after walking Chris Carter. Dexter Fowler beat out an infield single to load the bases for Castro, who sent a 2-0 fastball over the right-field wall.
"Just trying to be as short as I can and trying to put the ball in play," Castro said. "I was really just looking to get something I could drive in the air so that worst-case scenario, we had a sac fly, and luckily enough I got the barrel on it and I was able to put a short swing on it, and it was able to go out."
McHugh allowed six hits and two runs through three innings, but fate wasn't on his side. He gave up a couple of weak hits to start the game, then gave up a run when Mike Carp hit into a double play. Three consecutive singles to start the third, including a bunt hit by Elvis Andrus, loaded the bases with no outs.
Carp hit a sacrifice fly to left field to put the Rangers ahead, 2-0, before McHugh came back to struck out Adrian Beltre and Jim Adduci. He went on to retire 15 of the final 18 batters he faced.
"We had some situations, but [McHugh] made some good pitches," Andrus said. "When you face a guy for the first time, sometimes you have the advantage, and sometimes you don't. He just made good pitches. The next time we'll know him better."
Andrus shouldn't feel too badly. McHugh has taken just about everybody by surprise this season, lowering his ERA to 2.99 in 21 starts.
"He did a tremendous job," Porter said. "Those two strikeouts there, when they had the major threat, those were huge to get out of that situation. You look at the body of work for those seven innings, and I felt he did a really good job with his slider and his curveball. He was able to throw it ahead in the count, behind in the count, throw it to chase -- just did a tremendous job all the way around."