Basically, trauma to the recurrent laryngeal nerve (RLN) causes hoarseness among other symptoms. How the trauma comes about can vary from patient to patient. Sometimes the nerve is injured indirectly. This can happen when it gets pinched between the surgeon's instrument and the endotracheal tube holding the patient's airway open.
The nerve can also get stretched when the surgeon uses retractors to pull the muscles and tissues out of the way. In a few cases there's no known cause.
The best way to avoid damage to the RLN is for the surgeon to locate the nerve early in the operation and protect it. Making sure the nerve doesn't get stretched, pulled, or pressed is important. It's also important to make sure the blood supply to the nerve doesn't get cut off at any time.