Martinez connected off Masahiro Tanaka with two outs in the first inning. He struck out looking in the third inning and led off the fifth with another homer against Tanaka.
Martinez then went deep off Danny Burawa with two on in the sixth to give the Tigers an 11-2 lead. Burawa was making his major league debut.
"It was just one of those days where you take swings and you're actually hitting the ball how you want to hit it," Martinez said. "There's not too many of those days, so you've just got to take advantage of them."
With a chance to tie the major league record, Martinez flied out to right in the eighth.
"I definitely got anxious. I just knew that I was feeling good," Martinez said. "I don't think he threw me one strike."
This was the first multihomer game of Martinez's career and the first three-homer game for Detroit since Miguel Cabrera did it at Texas on May 19, 2013.
Martinez became the first Tigers player to connect three times against the Yankees since Charlie Maxwell in 1959.
"It's pretty cool just to say the first time you did it was here,'' J.D. Martinez said. "This is the pinnacle of baseball.''
Martinez is the fourth player to have a three-homer game this season, joining the Cincinnati Reds' Joey Votto (vs. the Philadelphia Phillies on June 9), the Washington Nationals' Bryce Harper (May 6 the Miami Marlins) and the Los Angeles Dodgers' Adrian Gonzalez (vs. the San Diego Padres on April 8).
The Associated Press contributed to this report.