Thorin acquired the title long before he became King. When he was just fifty-three (a young age for a Dwarf) he marched with a mighty Dwarf-army to the valley they called Azanulbizar, Nanduhirion beneath the East-gate of Moria. There they fought the Battle of Nanduhirion, the last and greatest in the War of the Dwarves and Orcs. In that battle, Thorin's shield was broken, so he cut a bough from an oak-tree with his axe, and used that instead to fend off his enemies' blows, or to club them. It was that oaken branch that gave Thorin his surname, but it did not completely save him from injury - it is recorded that he was wounded in the battle.
That is the legend of Thorin's surname within Tolkien's tales, but in fact it comes from a real-world source. Like many Dwarvish names, it appears in the Norse poem Völuspá in the form Eikinskjaldi, but there it is the personal name of a Dwarf, not a surname as in Tolkien's work.