Ravana was a devout follower of Lord Shiva. After attaining the education, Ravana underwent an intense penance to please Lord Shiva.
To appease Lord Shiva, Ravana even chopped off his head. Each time he chopped off his head, it grew back, thereby enabling him to continue his penance.
This austerity of Ravana pleased Shiva, and he granted him ten heads. And thus, he became one of the most powerful beings on the earth.
The ten heads of Ravana indicate the four Vedas and six shashtras that Ravana mastered.