The reason for the re-emergence of the ram in the mid-1800s is essentially a technological one. The introduction of the nautical steam engine gave ships a reliable source of power and the ability to move in any direction, and the introduction of armor-plating gave them greater weight (and therefore momentum), structural strength and protection.
During the Age-of-Sail most warships were wind-powered, square-rigged ships and, almost exclusively, had a broadside armament. This leads to several limitations;
Windpower limited the maneuverability and speed of these sailing warships. This could mean that a ramming attack might be impossible simply because the wind would not take you towards an enemy vessel or would do so at a speed that was too low to be effective.
Aiming your ship at the side of another to get a good square-on ram would mean that the bow of your ship (one of the weakest parts) was exposed to the full broadside of the enemy ship who was free to fire raking shot along the length of your ship as you approached.
The design of a square-rigged sailing ship meant that in a ramming situation, the ship doing the ramming would almost certainly lose its own bowsprit, effectively crippling its own sailing ability and weakening the whole of the ship's rigging.
So all in all, ramming in a sailing warship wasn't a good idea. However, once reliable steam engines were available, ships were no longer dependent on the wind and wind direction, and (in theory) armor protection meant that they could approach their targets at less risk.
It should be noted that the transition from wind power to steam power did not happen overnight. When the first ironclad rams appeared many of the warships in the world were still of the traditional wooden sailing variety (as were almost all of the merchant ships) or simply had an armor belt above the waterline with a wooden hull beneath. In theory, the steam powered ironclad should be able to out-maneuver the sailing ship and then use its ram to punch through the weaker wooden side of the target (so saving its expensive ammunition for stronger foes).
As to why it disappeared, it's a mix of tactical and technological reasons. As mentioned in other answers, in reality, actually getting into a position for an effective ram during a battle at sea was difficult and was almost as big a risk for the ship performing the ram as the target. This was realised fairly early on as noted by E.J.Reed (a British naval architect) in 1869 -
In order that a ship may be efficient as a ram, it is obvious, first of
all, that she must be handy under steam. The effect of the blow she
can deliver is in a large measure dependent on the directness of her
attack, and an oblique or glancing blow on an enemy's side might
sometimes do as much damage to the ram herself as to the ship she
attacks. When a vessel steams directly down upon a ship at rest, as
the 'Merrimac' did upon the 'Cumberland' at Newport News, or upon a
vessel which can only maneuver sluggishly, as the 'Ferdinand Max' did
upon the 'Re d'Italia' at Lissa, the attack by ramming can scarcely
fail to be successful. But when an enemy is under way, and is
perfectly under command of the steersman, there is much opportunity
for her either entirely or partially to evade the attack of the ram,
unless the latter is being maneuvered much more rapidly.
Just as there were improvements in ship's armor, there were also improvements in ship's armaments. Technological improvements in mechanization, metalurgy and chemistry lead to bigger guns, firing larger, more destructive shells over greater ranges and at higher velocities.
This meant that naval battles were fought at a distance and the pistol-shot pell-mell battles of the age of sail were a thing of the past. So in most cases warships simply didn't get close enough to ram each other and the designers realised that there was little point in adding a big chunk of metal to the bow that wouldn't get used.
refs:
The Sail and Steam Navy List, D.Lyon/R.Winfield (NMM/Chatham, 2004)
The Old Steam Navy, Volume 2, The Ironclads, 1842-1885, D.L.Canney (Naval Institute Press, 1993)
Our Iron-clad Ships, E.J.Reed (John Murray, 1869)
Development of Naval Guns 1850-1900, N.J.M.Campbell in British Naval Armaments, ed R.D.Smith (Royal Armouries, 1989)
Shells and Shell-Guns, J.A.Dahlgren (King & Baird, 1856)