The Tigers received right-handed pitching prospects Alex Lange and Paul Richan in the deal. The Cubs also will receive cash considerations.
"The guy is a good hitter," Cubs manager Joe Maddon said of Castellanos on Wednesday. "I always thought he patterned himself after [Miguel] Cabrera, early on. Saw a lot of balls go into the gap."
Castellanos is hitting .273 with 11 home runs and 37 RBIs this season. His best season came in 2017, when he hit 26 home runs and drove in 101 runs with a .272 average.
He was a late scratch Wednesday afternoon, informed of the trade just before the Tigers played the Angels.
"I'm very excited to be able to go to Chicago and help this team in a pennant race any way that I can,'' Castellanos told reporters in Detroit.
The 27-year-old should provide a big boost offensively to a Chicago team tied with the Cardinals atop the NL Central. His 119 doubles the past three seasons trail only Red Sox star Mookie Betts' total in that span. Castellanos has 37 doubles this season, which puts him tied with Boston's Rafael Devers for the most in the majors.
"When you watched us play over the last few months, it felt, at times, we were a bat short in the lineup," Cubs general manager Jed Hoyer said in a conference call. "He kills lefties. That's something we've really struggled with. We think he's going to give a pro at-bat versus righties and lefties."
The Cubs are 9-13 when a left-hander starts against them and have the third-worst batting average against lefties this season, at .235. Castellanos has mashed lefties throughout his career, especially this season, in which he is hitting .347 against them.
Maddon isn't sure where he'll hit Castellanos in the order, but his .357 on-base percentage while batting second this year is very enticing. He'll be in uniform on Thursday when the Cubs complete a series against the Cardinals.
The move was completed just ahead of Wednesday's 4 p.m. trade deadline.
Richan, 22, is 10-5 with a 3.97 ERA in 17 starts, and Lange, 23, is 1-9 with a 7.36 ERA in 11 starts at Class A.
The Cubs agreed to two other trades Wednesday. Chicago sent catcher Martin Maldonado to the Houston Astros for utility man Tony Kemp and traded right-handed reliever Carl Edwards Jr. to the San Diego Padres for left-hander Brad Wieck.
The move for Kemp fills a hole the Cubs have had since they traded Tommy La Stella to the Angels over the winter.
"Our position player group has felt a little short," Hoyer said. "We've lacked the depth of at-bats recently. That was something we were looking to restore at the deadline."
Kemp has a less than 2-to-1 strikeout-to-walk ratio, and his contact rate has never been below 82%.
"Our swing-and-miss rates are too high," Hoyer said. "Finding a guy that put the ball in play, that's really important for us. It's something we've lacked, especially coming off the bench."