The cabbie is indeed shown to be terminally ill and wants to raise money for his family.
However, this only explains why he resorts to killing people (=earn money fast).
Motives of Moriarty are part of the bigger overall story arc in the Sherlock Holmes universe as Moriarty is the arch-nemesis of Sherlock.
The poison pill trick is not random.
The cabbie is skilled in reading and manipulating people.
He has analyzed what drives his victims and acts accordingly.
He knew Sherlock would get in his cab instead of calling the police.
The poison pill trick is his way of showing he has control through his skill.
His victims can make the choice but as they are choosing, the cabbie manipulates them.
He knows which of the bottles is poisonous and will manipulate his victims into taking the bad bottle.
If they take the good one, he will convince them to change their mind.
This shows of how good the cabbie is in reading people, predicting their train of thought and knowing what to say to mislead them.
It takes great skill to manipulate people that know you are trying to kill them.
His confrontation with Sherlock is a battle in the understanding of human behavior.
It is a match to decide who can better see through the other's act.
They have layers and layers of bluff/misdirection in all the small details of their actions.
movies.stackexchange.com/users/2155/Origin
The killer was terminally ill with a brain aneurism and could die at any moment.
He was using the 'scheme' to raise money.
He was earning money from Moriarty, who was essentially sponsoring the cabbie to murder people in this manner.
Moriarty's motive is unclear, perhaps just to cause chaos, but more likely to get his name in front of Sherlock.
Essentially the cabbie had nothing to lose - so it was purely random which pill was poison.
On each occasion he had a 50% chance of winning.
As the only repeat player, the odds are that he would die within a few rounds, but a fairly good chance he would kill one or two in the process - raising money for his family.
He viewed himself as being expendable, likely to die at any moment anyway - an intelligent man, he viewed it as a risk worth taking.
[Alternative (not very serious theory): Perhaps he has built up an immunity to Iocaine powder ?]
movies.stackexchange.com/users/40/iandotkelly
There's another explanation although without evidence of course.
Neither of the pills were poisonous.
The poison was in a glass of water he would offer the victims to wash it down with.
He'd dry swallow the pill.
In my opinion it's one of the better answers.
However everything is entirely speculation so it could easily be wrong.
movies.stackexchange.com/users/5402/crazydrifter
Both pills have poison.
You see
but you do not observe!
The cabbie opens the bottle and holds the pill in his left hand.
He talks and distracts Holmes.
Just before he is shot you see him with a pill in his right hand.
He had a second, non-poison pill, all the time.
He did this with all the victims.
None had a chance, the game was rigged.
At time 1:19:36 the pill is in his left hand.
At time 1:19:54 the pill is in his right hand.
movies.stackexchange.com/users/5886/Guest
Could be the pills are his meds.
If he takes them it does nothing (they're prescribed for a reason), but when someone else takes them they die.
movies.stackexchange.com/users/5982/Vasili Andropolov
I heard my favorite theory on tumblr and expanded on it.
Neither pill was poison, and the water he gave them was.
He swallowed his dry.
This explanation has no evidence in the episode to support it, but it still fits the events and I like it a lot.
One problem that I noticed is that there is no water in the final scene where they are both about to take the pills.
One way to explain this is that the cabbie's sponsor Moriarty (who has been described as a 'fan' of Sherlock) did not want Sherlock dead.
If neither of them used poison water then neither one would die.
Presumably, the cabbie would fake his own death, let Sherlock think he had chosen right, and then who knows?
movies.stackexchange.com/users/5630/Cooper Wiseman
This is covered in the episode, Holmes mentions it to the cabbie and the cabbie replies something like:
Four games and four wins, that's not random
If you want an excellent, explained example of this in
action - watch
The Princess Bride: http://www.youtube.com/watch?v=U_eZmEiyTo0
The man in black's intelligence test.
He provides two vials, one of which is poisoned.
Vizzini explains his chain of thought thus expressing how he feels that the placement of the poisons is not random but is a psychological trick.
In the same way the taxi driver feels that there is psychology in the way he plays his 'game' and that it is not random - whether either if them are right or wrong is not the point, the point is that they feel there is more to it than random chance
Note: the twist in the Princess Bride's version about immunities is not relevant to the Holmes's version.
I only included this as it explained the chain of thought as to which glass should be drunk from.
movies.stackexchange.com/users/1501/Stefan
In  Sherlock season 1 episode 1  the serial killer asks Sherlock to take one of two bottles. 1 bottle is ok other is bad (poisonous). Whatever bottle Sherlock takes the serial killer takes the other one. That is same way the serial killer murdered his other victims.   But the episode doesn't say  how exactly serial killer achieved this. Before Sherlock can take one of the bottles the serial killer is murdered.   Does anybody know how the serial killer achieved this?
In Sherlock: Study in Pink how does the choice of bottles work?
movies.stackexchange.com
<plot-explanation><sherlock>
movies.stackexchange.com/questions/10432
movies.stackexchange.com/users/3559/minusSeven
There is another explination although without evidence of course.Neither of the pills were poisonous. The posison was in a glass of water he would offer the victims to wash it down wih.  Neither of the pills were poisonous.
There's another explanation although without evidence, of course. Neither of the pills were poisonous. The poison was in a glass of water he would offer the victims to wash it down with. However everything is entirely speculation so it could easily be wrong.