John the Baptist confered the Aaronic Priesthood on the heads of Joseph Smith and Oliver Cowdery on May 15th 1829. After baptizing each other they ordained each other to the office of a Priest in that Priesthood, which office gives them the keys to baptize. By what keys did they have to be able to baptize prior to being ordained to the office of a Priest?
When Joseph Smith and Oliver Cowdery received the Aaronic priesthood, it was conferred upon them slightly different than we practice today. John the Baptist conferred the priesthood upon them, but he did not ordain them to an office. Rather, they were given all the keys of that priesthood, not only the ones pertaining to an office. You may also notice that while the Aaronic priesthood was restored on May 15, 1829, the office of priest as we know it was not fully defined until April of 1830.
So, the authority to baptize each other was given to them when they received all of the rights, powers, and authorities of the Aaronic priesthood. It wasn’t until later that the offices were defined that limit the authority of a person to exercise that priesthood.