Coghlan also tripled and scored two runs for the Cubs, who have won four of their last five.
Edwin Jackson (5-7) picked up the win, just his second in his last six starts, despite allowing three runs on five hits and two walks in five innings. He had eight strikeouts.
Jordy Mercer had a three-run homer for the Pirates, who have dropped four of five.
Charlie Morton (4-8) had a three-start winning streak snapped, yielding six runs on eight hits and two walks in six innings.
Gregory Polanco led off the game with a single, extending his own Pirates record by hitting safely in his first 10 major league games.
The Cubs took a 5-0 lead in the third inning after Anthony Rizzo roped a two- run double into the right-field corner with the bases loaded and Castro teed off on a low pitch for a three-run blast, his 11th homer of the season.
Mercer stroked his fifth homer of the season to left field in the fifth after Josh Harrison and Pedro Alvarez started the inning with consecutive walks but Coghlan led off the bottom of the inning with his second homer of the season to get one of the runs back and give the Cubs their 6-3 lead.
There were two replay reviews early on.
The Pirates successfully challenged a call in the first inning to take a run away from the Cubs. Replays showed Rizzo was hit on the back foot by a pitch he swung through that eventually went to the backstop. Coghlan, who tripled, was sent back to third base.
In the second inning, a call at home plate was upheld after Ike Davis tried to score from third base when Alvarez was caught in a rundown following a single. Cubs catcher John Baker blocked the plate to tag Davis out.
Celebrity Breakups and divorces of 2014 [PHOTOS]