In the Second Age, Isildur brought with him a three meter tall stone as a symbol of his lineage and Gondor. He set it on a hill in Erech. He made the local hill tribes swear an oath of loyalty on the stone. The hill tribes later broke their oath and were doomed to haunt the place as the Dead Men.
The city was completely abandoned by the end of the Third Age, when the heir of Isildur, Aragorn, came to Erech to hold the Dead to their oath again. This time they held true to their oath and formed the Host of the Dead to help Aragorn defeat the Corsairs of Umbar at Pelargir.
After the battle at Pelargir, Aragorn released them from their oath and they were allowed to rest.