Here are the official MLB rules on this scenario:
When there is a tie for a Division Championship and the breaking of the tie will result in the losing team nonetheless being the Wild Card team, the Division Champion shall be:
A) The team with the better record in head-to-head competition, or in the event the teams have the same record in head-to-head competition,
B) The team with the better record, based on winning percentage in intradivisional competition, or, in the event the two teams have the same intradivisional winning percentages,
C) The team with the better record in League competition over the last 81 games played by each team, or, in the event the two teams have the same records over this period,
D) The team with the better record in League competition over the last 82 games, provided that the 82nd game was not a game between the tied teams.
If necessary, the subparagraph (D) procedure of adding the immediately preceding game played by each team records shall be continued until such time as one team emerges with a better record and that team shall thereupon be declared the Division Champion and the other team shall be declared the Wild Card team.
In other words, there's no playoff game if the team that loses would still have the best winning percentage of the non-division winning teams.
If however losing a playoff game would eliminate the team (i.e. after losing the playoff game the team does not have the best winning percentage of the remaining non-divison winning teams) then a playoff game is played between the tied teams.
Again, the official rules:
When there is a tie for a Division Championship and the breaking of that tie will result in the losing team(s) not being the Wild Card team, the tie for the Division Championship shall be broken as follows:
A) Tie between two teams. The League President shall conduct a coin flip to determine the site of a playoff game between the two teams, the game to be played the day after the conclusion of the championship season. The winner of the game shall be declared the Division Champion.
Paragraphs B and C go on to describe how to break three way and four way ties, respectively.
If you're wondering what happens if two teams are tied for the division title, and have the same record as a 2nd place finisher in another division, then this is what happens. A playoff game is played between the teams tied for the division title. The winner becomes the division champion and the loser is eliminated from post-season contention. Why? Because tie-breaking playoff games such as this are counted in the standings, and since they lost the playoff game, their winning percentage is now lower than that of the 2nd place team in the other division.
Things start getting really complicated once you start getting into 3 way ties, so don't ask LOL.