The Rangers had erased a 4-0 deficit in the sixth, thanks to a sacrifice fly by Mitch Moreland and three-run homer from Geovany Soto.
But the Astros came right back in the next half-inning. Jose Altuve drew a leadoff walk, chasing Texas starter Yu Darvish, and Brett Wallace was hit by a pitch from reliever Robbie Ross.
Castro, named to his first all-star team earlier Saturday, then followed with a blast to right-center and the Astros went on to even their three-game series.
Marc Krauss went 3-for-4 with two RBI while Brandon Barnes and Jake Elmore each added a two-run homer for the winners.
Travis Blackley (1-0) notched the decision with 1 1/3 scoreless relief frames.
Darvish (8-4) was saddled with the loss, allowing five runs on six hits and four walks in six innings.
Nelson Cruz went 3-for-4 with a solo homer for Texas, which remained a half-game behind American League West-leading Oakland.
Beautician charged with giving client fatal silicone butt injection
McPhee, Cokas 'working on their marriage' after affair