After Legolas clearly hated Thorin Oakenshield, why did he save him? I mean considering that at the beginning of the movie Thorin hated all Elves, but at the battle of the five armies when he was about to get killed, Legolas threw that sword up and killed the orc. Didn't Legolas hate Dwarves?
In the Director's commentary, Screenwriter Philippa Boyens and Director Peter Jackson discuss both the in-universe and out-of-universe reasons why they chose to have Legolas sacrifice his sword to save Thorin. The very short answer is that it boils down to two factors; that the elves hate the orcs far more than they hate the dwarves (and by this point, have abandoned their enmity to team up against the greater threat, the orcs) and that they needed to somehow get the Orcrist sword back to Thorin so he could have it in later scenes.
PB: You know, another corner that you painted yourself into, and had to figure out was that that bloody elf [Legolas] has Orcrist, hasn't he? And you always wanted to get that back to . . .
PJ: Yeah, because Orcrist is ultimately Thorin's sword and he had it confiscated in the forest but we somehow had to figure out a way to get that back, and that's obviously coming up shortly
a few minutes later
PB: I like that in the end that it is the elves and the dwarves fighting against the orcs, side-by-side, even if it has just come down to these two. Which feels true to the book.
PJ: We're emerging from our 'Orcrist Corner' here, Philippa
PB: You did.
PJ: We did! [Legolas throws the sword. Peter Jackson starts yelling at Thorin on-screen] Come on! Grab it!! As long as he grabs it, we've given him every opportunity to get his sword back. He did it!
You may wish to note that while the dwarves and elves have historically fought (for the usual mix of land, power and position) neither represents an existential threat to each other. If the dwarves win this battle, they won't go and murder the elves back home whereas the orcs will quite happily do so.
I don't think it's just a matter of counting whom they hate more. I think they recognize that, while they have their differences and tensions between them, elves and dwarves and basically on the side of Good, vs. orcs, trolls etc. who are on the side of Evil. In fantasy, this distinction is real.
I see the elf-dwarf enmity as similar to what you see in modern-day friendly neighboring nations (e.g. France/England, Scotland/England, US/Canada, Australia/New Zealand, Scandinavians etc.) - they can make fun of each other, and they can dislike each other, but they'll still feel committed to protecting each other from, say, ISIS, because they recognize that "They" are on the same side, whereas ISIS is on the side of Evil.
To repay Thorin for having saved Legolas earlier in the barrel fighting scene.