Conventional wisdom says that democracy is the superior form of government.
If this is true, then factors might have contributed to earlier democratic states like Athens in 500 BCE and the Roman Republic failing?
I'll answer just the part about the Roman Republic, if that's alight for now.
The Roman Republic is probably best described as a pseudo-democracy of sorts. Its creation and initial set-up actually pre-dated Athenian democracy by a single year, though even until its dying days it was more of a "democracy for the privileged" than anything. Hence, Classical-period Athens is usually considered the world's first true democracy. Nonetheless, the Roman Republic was clearly a very successful model for a state. It was ultimately the lack of fail-safes and precautions against powerful consuls and leaders that led to its down-fall, and arguably the fact that only landowners had a say in the vote, or indeed only equestrians (members of the ancient noble families) could become senators or consuls. Your average peasant, born in Rome or otherwise had little say in the state.
Generally seen as the first real sign of the downfall of the Roman Republic was Lucius Cornelius Sulla's stint as dictator (to use the actual Latin word). Dictator was a special privilege granted to a military leader (general) by the Senate -- often a past consul by nature of the office -- in times of great need. For example, during the Sack of Rome in the 4th century B.C. by the Cisalpine Gauls (of northern Italy). It was however used extremely sparingly until Sulla was granted the position during the Roman Civil War of ~82 B.C. (the very worrying second one in the span of a decade). The senate relied on the honour of the general to relinquish the title of dictator when it was no longer required and return to normal life (of a senator often).
Fortunately at first, Sulla did this, though as we all Gaius Julius Caesar did not and craved power until his final assassination. Ironically, Caesar was known as a member of the populares (unlike his aristocracy-aligned rival Pompey [Gnaeus Pompeius] of the First Triumvirate), gaining widespread support from the working class, and thus facilitating the end of what small democracy there was, and the start of Octavian's tyrrany. I hope you can see from this that effecitvely the collapse of this pseudo-democracy was facilitated greatly by the lack of sufficient legal codes as well as increased internal strife within Italy, propagated by corrupted and varying degrees of oligarchic control. There were always too many loopholes in Roman politics and law to allow power-hungry men to wield disproportionate control. One might say the Roman Republic was a time bomb ready to explode (though not as disastrously as the Roman Empire of course!).
A lecture summary for a history course on Classical History in the Purdue University gives a good summary and highlights four main causes (in the lecturer's view, though largely accepted by historians I'd say):
All contributed to increase oligarchy and eventual pseudo-monarchy in the Roman Empire. The natural response to the many crises that occurred over the first century B.C. was to put power in the hands of great individuals; a dangerous move at any time, despite it having some logic. No doubt, the spiral towards collapse had begun long before Caesar's heydey. Worth noting: the first Emperor Octavian cunningly maintained the pretence of the Republic's continuation, gradually dropping it towards the end of his reign.
Now there are of course other explanations, and I have only touched on the surface here, for it is a highly complex subject, but I hope this gives some insight for you to go and read around the matter further, at least.
Democracies were not necessarily more stable than other forms of government. Polybius describes a cycle of three forms of government - monarchy, then aristocracy, then democracy, then back to monarchy again (of course, this was not always the case in practice). The important point to note is that each first degenerates into an inferior form (tyranny, oligarchy and mob rule respectively) before being replaced. Wikipedia gives a good overview:
Polybius considered the Roman Republic to have the best and most stable form of government - mixed government combining facets of monarchy, aristocracy and democracy, each being able to check the power of the others. However, less than a century after he wrote these words, the Republic was on its knees.
As Noldorin says in his answer, Rome wasn't particularly democratic and there was a long history of struggle between the rich and the poor. Appian traces the beginning of the end of the Republic to the assassination of the tribune Tiberius Gracchus, to his knowledge the first instance of the regular class struggles descending into internal conflict. Both Tiberius Gracchus' and others' proposals for the improvement of the lives of the poor met with vigorous and sometimes violent opposition by the wealthy, so the poor would have had little interest in maintaining a system that did not work for them.
The reforms of Gaius Marius introduced to the army soldiers the poorer parts of the citizenry who did not previously meet the land holding requirements. While nominally servants of Rome, their hopes of wealth and a comfortable retirement rested upon the success of their commanders not only in battle but also in securing lucrative political appointments. This opened the door to Marius and others after him to build personal armies to back their bids for power. Noldorin has covered the subsequent events well so I won't go over the same territory.
The democracy of Athens was briefly replaced by an oligarchy during the Peloponnesian War before returning to democracy. After losing the war, Athens camed to be ruled by another oligarchy in the rule of the Thirty, this time imposed by pro-oligarchy Sparta. It idnd't take long for Athens to again return to democracy. The later demise of this democracy was again due to external factors - conquest by Macedon and Rome.