Castillo struck the winner in the 74th minute but he was shown a red card 10 minutes from time, with Bari's Sergio Almiron already dismissed for two bookings.
In other games, Atalanta won 3-1 at home to Parma, Lazio lost 2-0 at Bari and Cagliari continued early-season leaders Genoa's poor recent run with a 3-2 home win.
Midfielder Sergio Almiron sealed his former club's fate with a long-range effort that eluded goalkeeper Gianluigi Buffon in the 86th minute to give Bari their first win over Juve since 1990.