Jason Castro’s three-run home run in the seventh inning lifted the Astros to a 4-1 win over the Pirates.