It is more obvious in the book than the movie, but when the Rohirrim engaged the Orcs, the Orcs were terrified and more interested in running away than fighting (in fact, in the book, the Rohirrim are so confident that, rather than killing the Orcs as soon as they catch up to them, they encircle the Orcs, set up camp, and go to sleep, then wait for sunrise before beginning the slaughter; the Orcs don't attempt to attack during the night, but some of them do try to break out and flee - unsuccessfully).
The Rohirrim had the upper hand and everyone knew it. The books say that there were 200-300 Orcs against a much smaller force of Rohirrim, yet the Rohirrim killed every last Orc and suffered only relatively minor losses - just 15 men died, compared to 200-300 Orcs.
In such a lopsided battle, the Rohirrim were confident enough to throw spears willy nilly and use their swords more than they would have if the enemy posed a more formidable threat. It was almost like shooting fish in a barrel. And of course, a spear designed for throwing - also called a javelin - is very different from a spear designed to be held and thrust at an enemy. Throwing spears are shorter and lighter; thrusting spears are longer and heavier. Trying to use a throwing spear or javelin as a lance will likely result in a broken spear.
In general, human warriors (and elf warriors, and dwarf warriors) in Middle-earth are far more skilled and formidable than Orc warriors (again, this is more obvious in the books than it is in the movies). Orcs are terrifying, but there is a reason they tend to focus on raiding and pillaging civilian settlements, farms, etc, rather than engaging in set piece battles against hardened troops in numbers similar to their own - at least when they have a choice. Killing women, children, old people, farmers, shopkeepers, etc, is a hell of a lot easier (and safer) than fighting against experienced warriors who know you're coming and have swords of their own.
Orcs are brave when they have a huge numerical advantage or when their targets are frightened, defenseless civilians, but in a fair fight against actual soldiers, they tend to be easily routed. Imagine a street gang - they are tough enough to squabble with other gangs and terrorize their neighborhood, but how do you think the Crips would fare in a battle against the Marines? Not very well. In fact, they'd be wiped out in a few seconds. The same basic dynamic loosely applies to Orcs - they're like a gang, and they can only hold their own against civilians or wildly outnumbered warriors.
The Rohirrim know all of this, and fight accordingly. They knew that they would win without breaking a sweat, so they killed the Orcs off in the easiest manner possible. Throwing a spear or two wouldn't affect the outcome either way, so there was no reason not to throw it.