Ramming dates back to antiquity. Wooden triremes rammed their enemies, often with the intention of boarding the enemy ship and killing its crew. The Romans invented the corvus, a wooden plank with a nail on its end, to board an enemy vessel. This required closing to point-blank range. Even after the development of ranged weapons, ramming continued to be used because of the two-dimensional nature of surface naval combat, and the lack of sufficiently powerful weapons.
Ramming was often used as a desperation tactic. In the early days of ironclads, commanders of ships-of-the-line believed ramming was a viable tactic. Fleet commanders studied the Battle of Lissa in 1866 and drew the incorrect conclusion that ramming could defeat ironclads. However, weapons development eventually made closing to point-blank range a suicide tactic.
Attempting to ram or even closing the distance to point-blank often ends in failure with more modern warships. The HMS Hood attempted to close the distance between herself and the Bismarck in World War II. The British knew the Germans had the advantage at greater range, and wished to limit exposure to the Bismarck's powerful guns. However, the Bismarck's weapons were sufficiently powerful and the Hood was sunk before it could close to its optimal distance.
Ramming is often used by inferior opponents to catch unprepared superior opponents by surprise. For example, the suicide bombers which damaged USS Cole closed to point-blank range, and in WWII Japanese kamakazie pilots rammed US naval ships. However, ramming has not been a decisive factor in any major naval engagement since the development of layered defenses. Modern warships have sufficient point defense to discourage suicide attacks, such as the Phalanx CIWS on US warships.
Newton's Third Law states that for every action there is an equal and opposite reaction.
In the context of ramming, that means that the force applied by the ramming ship to its target is equal to the force applied by the rammed ship to the ramming ship. Often, proponents of ramming are under the misassumption that ramming will inflict more damage on the defender, simply by virtue of being an aggressor. This is not the case, as a ramming ship will have as much force applied to it as the rammed ship.
Therefore, physics dictates that ramming is only useful if the ramming ship is prepared to withstand as much force as it will apply to its target.
Star Trek Ramming
The USS Odyssey was rammed by three Dominion ships. These Dominion vessels had already inflicted enough damage to give the Odyssey's commander grave doubts, and the Odyssey was in full retreat. Nevertheless, the Dominion ships rammed, possibly to send a message to the Federation that the Dominion was prepared to go to any length to defend its territory. No other Galaxy-class vessels were destroyed on-screen in many of DS9's major fleet battles.
In an alternate timeline, the USS Voyager rammed the Krenim's time-ship in an effort to destroy it. Voyager herself was totally destroyed by the collision, but the Krenim ship remained mostly intact. Fortunately, the ramming caused the ship to malfunction and remove itself from the timeline, which restored Voyager to existence.
The USS Enterprise-E rammed the Scimitar in Star Trek: Nemesis. The Enterprise-E was defeated, and approached the Scimitar with thrusters. Shinzon did not order evasive maneuvers until the last second. The already-damaged Enterprise-E was left totally disabled in the aftermath of the attack (even an attempt at self-destructing failed due to computer damage); the Scimitar received some significant structural damage, but most of its primary systems seemed to remain operational.
Federation starships rely on forcefields to maintain structural integrity. Structural integrity fields are likely engineered to provide as much strength as needed (within their technological limits). Any additional load on a structural integrity field could cause catastrophic failure, as in the case of USS Odyssey. An ad-hoc solution is to boost power to the SIF and kinetic shields, as was likely done in later Galaxy-class vessels to reduce the effectiveness of Dominion kamikaze attacks.
Star Wars Ramming
The most famous example of Ramming in the SW universe is the fate of the Executor. At the Battle of Endor, Executor received a fearsome pounding from Rebel cruisers at point blank range that caused a loss of shielding around the bridge. This hole in the Star Dreadnought's defenses allowed a single, barely controlled A-wing fighter to crash through the bridge tower, killing the ranking officers and throwing the ship into chaos. Although the damage inflicted was minor, it was ultimately fatal.
One final note of worth would be the Rebellion's use of transports as fireships at the Battle of Endor. These were loaded with explosives and sent into combat, presumably under remote control. No impacts by such ships were observed.