The purpose of a guru is to guide the student on their spiritual path. The guru is more than a teacher: he/she makes the student aware of their true potential.
Nearly every yogic text mentions the importance and necessity of a guru. The "Hatha Yoga Pradipika" instructs: “Yoga should be practiced in the way instructed by the guru” (chapter 1, verse 14). Here, “yoga” does not refer to asana, but to the entire process of spiritual growth.
A guru is the ignitor of the student’s sadhana, or spiritual practice. He/she is the illuminator of darkness. Broken down, gu means "darkness" and ru means "light." The guru’s guidance clears away the clouds that cover the student’s consciousness and keep him/her in a state of ignorance. It is through the guru’s own enlightenment that they can awaken the student’s consciousness, enabling him/her to see the luminosity and potential of his/her own spirit. Without the guru, the student may not ever know his/her full capacity for spiritual growth, nor how to achieve it.
(Related question: What does guru mean?)
The guru is not just a yoga teacher, and may not be a yoga teacher at all. His/her expertise does not matter; it is his/her ability to illuminate the student’s spirit that is important. Equally important is the student’s faith in the guru. Like a blind man being led by the hand of one who can see, the guru guides the student toward enlightenment through his/her own awakened spirit. The student must follow the guru’s instructions with complete trust; and through this trust, all of the guru’s guidance becomes fruitful.
(Read on for the answer to a related question: Do I need a guru?)