Marcus Tackett (0-1) gave up Castro's homer after following Texas starter Kenn Kasparek, who gave up two runs on five hits in four innings.
Jordan Danks went 2-for-4 for the Longhorns (9-3), and Russell Moldenhauer had two RBIs.
Castro finished with three RBIs for Stanford.
- Send us your sports story tips
- Click here for more sports stories