Jarred Cosart (2-3) allowed two runs and eight hits over six innings for the Astros, who had lost seven of eight before ending Baltimore's five-game winning streak.
Castro hit a three-run homer off Chris Tillman (3-2) in the first inning and Krauss connected against T.J. McFarland with a runner on in the seventh. Houston is 11-11 when it hits a home run and 1-15 when it doesn't.
Jose Altuve had three hits for the Astros, who improved to 6-12 against the Orioles - including 2-10 at Camden Yards.
Adam Jones drove in both Baltimore runs, giving him 501 RBIs in 981 career games.
Before the game, the Orioles activated Chris Davis (strained left oblique) from the 15-day disabled list and put catcher Matt Wieters on the DL with a strained right elbow. Davis went 2 for 4 in his first game since April 25.
Tillman gave up three runs, four hits and a season-high five walks in five innings. The right-hander settled down after issuing three walks and a home run in the first inning, but needed 105 pitches to get 15 outs.
Houston took a 3-0 lead before Tillman retired a batter. After Altuve and Dexter Fowler walked, Castro hit the right-hander's next pitch over the center-field wall. Tillman has yielded seven first-inning runs this season, his most in any inning.
Jones hit a two-run single to get Baltimore to 3-2 in the third.
A double by Davis in the fifth put two runners in scoring position, but Jones struck out before Nelson Cruz flied out.
NOTES: The Orioles were denied consecutive three-game sweeps for the first time since 2005. They won three in a row at Tampa Bay before facing the Astros. ... The game drew 45,944 fans, the second sellout of the season at Camden Yards. ... Baltimore's Nick Markakis singled in the third inning to extend his hitting streak to 18 games, one short of his career high. ... Tillman's 399th and 400th career strikeouts came against George Springer in the first and third. ... Houston's Alex Presley snapped an 0-for-14 skid with a sixth-inning single. ... Bud Norris takes the mound for Baltimore on Monday night in the opener of a three-game series against Detroit. The Astros return home to face in-state rival Texas. ... Since coming to Houston from the Padres organization, Sipp has retired all 12 batters he's faced with seven strikeouts.