Hammel had a season-high seven strikeouts. He didn't allow a hit until Carlos Gomez doubled with one out in the sixth.
Hammel (4-1) then got into trouble after walking Scooter Gennett and making an errant pickoff throw to put runners at second and third. But the righty got a strikeout before Aramis Ramirez bounced out to end the threat.
Chicago scored twice in the second on Castro's first homer and Darwin Barney's RBI fielder's choice with the bases loaded. Castro's second shot in the eighth barely cleared the wall in the left-field corner.
Brewers starter Wily Peralta (3-1) allowed eight hits in seven innings.
The right-hander with a 96-mph fastball had trouble spotting pitches in the second and the Cubs took advantage in snapping a four-game losing streak. Ramirez stepped on third for an out on Barney's grounder but his throw trying to get Nate Schierholtz at home bounced up the first-base line to allow the run to score.
Braun sat with a slight chest muscle strain, while Segura had a partially closed right eye and bruised right cheek after being accidentally hit during a practice swing by Braun on Saturday.
Both players were considered day to day. The Brewers' bench was already down catcher Martin Maldonado, who was serving the last game of a five-game suspension for his role in a brawl in Pittsburgh last week.
The remaining Brewers were overmatched by Hammel, who mixed a fastball in the low 90s and stayed low and away from the Brewers' remaining potent right-handed bats. Hammel allowed three hits and two walks before being lifted after allowing pinch hitter Rickie Weeks' single to lead off the bottom of the eighth. Pedro Strop and Hector Rondon held the Brewers hitless the final two innings.
Hammel has been a bright spot in a dismal April for the Cubs, the last team in the majors to reach eight wins. Signed in the offseason to a one-year deal as a free agent, he hasn't given up more than five hits in each of his five starts.
Castro had his second career multi-homer game in nearly three weeks, having going deep twice April 8 against Pittsburgh. His second-inning homer was nearly caught by a leaping Gomez at the wall 400 feet away in dead center.
Gomez went 1 for 4 on his bobblehead day.
Notes: Despite the win, the Cubs lost the three-game series to the Brewers and extended the team's string of winless series to 13 dating to last season. Chicago last won a series after taking two of three from Cincinnati in September. ... C John Baker went 2 for 4 that ended an 0-for-18 stretch. ... Brewers manager Ron Roenicke said the club would hold off on making any roster moves while Braun and Segura continue to be evaluated. ... The Brewers travel to St. Louis to start a seven-game road trip, with Yovani Gallardo (2-0) getting the start Monday. Chicago begins a three-game set in Cincinnati and sends Jeff Samardzija (0-2) to the mound.