The Blue Jays (27-28) have won six of the first eight games of their 10-game homestand.
Toronto starter Francisco Liriano (3-2) returned from the disabled list to pitch five-plus innings, allowing two runs on four hits and two walks. The left-hander struck out five.
Liriano faced two batters in the sixth, allowing a single to Gary Sanchez and the 18th homer of the season by Judge.
Danny Barnes replaced Liriano and allowed a walk to Matt Holliday and the eighth homer of the season by Castro, cutting Toronto's lead to 5-4.
New York starter Michael Pineda (6-3) allowed five runs on 10 hits and three walks in five innings to take his first loss since May 11. He had one strikeout before Jonathan Holder replaced him in the sixth.
Donaldson hit his second homer of the game and fifth of the season with one out in the sixth.
After Aaron Loup struck out his only batter, Brett Gardner, to lead off seventh, he was replaced by Ryan Tepera, who walked Judge before giving up an RBI double to center by Holliday, trimming the Toronto lead to 6-5.
Roberto Osuna pitched a perfect ninth to earn his 12th save of the season.
The Blue Jays scored three runs on two homers in the bottom of the first.
Donaldson hit his fourth homer of the season with one out. Kendrys Morales walked with two outs and Smoak followed with his 13th homer of the season.
A sacrifice fly by Smoak in the bottom of the third gave Toronto a 4-0 lead. It scored Jose Bautista, who led off with a walk and took third on a single by Morales.
A wild pitch by Pineda in the fourth bumped the lead to 5-0. It scored Luke Maile, who led off with a single and took third on a two-out single by Bautista.
NOTES: Toronto RHP Leonel Campos was optioned to Triple-A Buffalo with the return of LHP Francisco Liriano (shoulder) from the disabled list. Campos had been recalled for the game Thursday and allowed two unearned runs, two hits and a walk in a career-high three innings. ... Yankees 1B Greg Bird (ankle) began his rehabilitation assignment Thursday with Class A Tampa, playing six innings at first base and going 1-for-1 with two walks. ... Blue Jays C Russell Martin (neck) missed his second straight game with what is being considered a minor neck issue. ... Yankees LHP Jordan Montgomery (2-4, 4.11 ERA) opposes Blue Jays RHP Joe Biagini (1-3, 3.64 ERA) on Saturday.