During the time of the Roman Republic, Romans were very proud of the fact that they were not ruled by a monarch. Their system of government was set up to prevent any one man from getting too much power. However, they did realize that there would be times when this sort of a system would be unwieldy. Because of this, they made it possible to appoint a dictator to run the state. This person would essentially have complete power in Rome for a given amount of time.
In general, the Senate only chose dictators in times of war. When there was a war that Rome seemed to be in danger of losing, a dictator would be appointed. His job would be to take whatever steps were necessary to win the war. One example of such a dictator was Cincinnatus. He was appointed dictator in 457 BC to fight against a people known as the Aequi. He defeated them and returned to his farm in just over two weeks. A second example would be Marcus Junius Pera, made dictator when Hannibal threatened Rome in 216.
Toward the end of the Republic, there were dictators who were not appointed to defend Rome against foreign enemies. Instead, these were dictators who forced the Senate to name them in times of civil war. Two examples of such people were Lucius Cornelius Sulla and, most famous of all, Julius Caesar, who was actually made dictator for life.
So, it was originally when Rome was faced by serious foreign threats that it created dictators. Later, dictators arose by force in times of civil strife.