How did John earn the power to baptize?
Water baptism was a common Jewish practice used to "symbolically wash" gentiles who converts to Judaism. So, when John started to baptize people with water, it was not something strange, the Jews understood... but John's baptism is also different. John's baptism was to call Israel to repentance in preparation for the coming Messiah.
I don't think it was a matter of John EARNING the power to baptize... he was born specifically for this reason. In the book of Luke, Chapter 1, vv 11 through 25 talks about the Angel of the Lord announces John' conception, birth, lifestyle and ministry.
Luke 1:15 states that...
For he will be great in the sight of the Lord... He will also be filled with the Holy Spirit, even from his mother's womb.
So, John's purpose was clear and well establish before he was even conceived... the angel also said that he will be "filled with the Holy Spirit." Throughout the Bible, both Old Testament and New Testament, these words usually meant that God, in the person of the Holy Spirit, was with John the Baptist... talking to him, teaching him, and most of all, gave him the power to baptize. In Luke, 1:41-46, It is written that "when Elizabeth (John's mom) heard the greetings of Mary, that the babe leaped in her womb."