Inter, who lost 2-0 at bitter rivals Juventus on Sunday, moved up three places on to 27 points, level with Atalanta in fifth and third-placed Lazio who host Monza on Thursday.
The visitors' joy was short-lived, however, as striker Edin Dzeko levelled four minutes later with a superb first-time shot from the edge of the box.
Simone Inzaghi's side added one more goal before halftime when Martinez nodded in a corner from midfielder Hakan Calhanoglu for his first goal in five games.
In the 48th minute, Dimarco netted again, evading his marker Joaquin Sosa inside the area and sending the ball into the bottom left corner.
Inter made it 5-1 through Calhanoglu's spot-kick, after the penalty was awarded for Sosa's handball, and Dzeko completed the rout with a tap-in in the 76th minute.
Substitute midfielder Kristjan Asllani could have further increased the scoreline but his powerful shot from outside the box hit the post.
Inter travel to Atalanta on Sunday for their last game before the World Cup break.
Bologna, who have earned just four points on the road this league season and are 13th in the standings, host 12th-placed Sassuolo on Saturday.