Consider the spatial voting model as a very simple mathematical model (made famous by Anthony Downs in, 'An Economic Theory of Democracy') imagine that voters care only about one topic. There is a one-dimensional variable X, and every voter has a preferred value. Given options, a voter will choose the one closer to his/her preferred value.
For example, my preferred value of X is 42. So if one party offers X = 30 and the other party offers X = 50, I will vote for the latter, because 42 is closer to 50 than to 30.
(There is usually an assumption that the voters' preferences are on a bell curve. However, for a model with one variable and two parties, this assumption is completely unnecessary.)
The winning strategy for a political party is to offer such value of X that exactly half of voters want more, and half of voters want less. (It's called median.) Here is why: Imagine that we have 100 voters, each of them wanting a different integer value from 1 to 100. My party offers 50. The opposing party offers 30. What happens? I will get the half of voters that wanted values above 50, and also the voters between 40 and 50; so I obviously win.
So in this model each party will try to offer the middle position, which is why both parties will offer almost the same thing. By moving closer to your opponent, you keep the voters on your side, and get a few more voters between your original positions. In the end, if voters want values from 1 to 100, one party will offer 50, the other one will offer 51, and both will get half of the votes.
Add a third political party, and the game changes dramatically. There is no universally best position, because it depends on what the other parties do. In the model where voters want values from 1 to 100, if one party offers 1 and other party offers 100, you win the election by offering 50. But if one party offers 49 and other party offers 51, offering 50 would be a losing move, and your best choice is 52... but this will make the party which offered 51 make change their strategy, etc. The parties will dance around, trying to get either inside the largest gap between other parties, or to the least-extreme extreme position if other parties get far away from the extremes. There is no stable solution, because in any position at least one party would prefer to change their offer assuming that the offers of the remaining two parties remain the same.
The weakness of this model is of course the original assumption. First, how much can user preferences be reduced to a one-dimensional variable? Actually, it seems they can (and the dimension is traditionally called "extreme left - moderate left - center - moderate right - extreme right"), although sometimes there are exception. Second, how much do votes depend on voters' priorities and parties' offers? In other words, how much rational the voters are. In my opinion, not much... they will vote even against their interests, just because e.g. the television told them to. This reduces the credibility of the model.
These videos explain the median voter theorem well.
Median Voter Theorem Animation
Game Theory 101 MOOC (#40): Hotelling's Game and the Median Voter Theorem
EDIT: Another weakness of this model is that it does not consider primaries, conflicts among candidates within each party. A candidate may choose a position which is better for him/her against other candidates from the same party, even if it is worse for the whole party. And if both parties have such candidate, one of them will win despite choosing a position suboptimal for his/her party.
Again, an example with numbers: Voters want values from 1 to 100. It would be optimal for a Low Party to propose 50, and for a High Party to propose 51. But let's say there are two candidates for the Low Party, L1 and L2. L1 chooses 50, which is best for the party. L2 chooses 45. What happens? In closed primary, the Low Party voters want values from 1 to 50, so 47 of them (numbers 1 to 47) will vote for L2, and only three for L1 (numbers 48 to 50). Similarly, in the High Party, a candidate H1 chooses 51 and a candidate H2 chooses 60; H2 wins against H1. Finally in the election L2 with number 47 wins against H2 with number 60. Both candidates L1 and H1 lost in primaries, despite the fact that without the internal competitor L1 would win against H2, and H1 would win against L2.
The lesson is, even if median positions are best for the party, they may be worst for the candidates in primaries. So probably the two-party system in itself leads to convergence of platforms, but primaries prevent too much convergence.