I was listening to a shiur and the rabbi said that Samuel knew Torah by the age of two. He didn't give any source for this, however.
Is there any source for what he said?
It's per a mishna and a gemara:
The mishna in Gittin 7:6 says:
"If a husband says to his wife: This is your bill of divorce on the condition that you will serve my father, or: On the condition that you will nurse, i.e., breastfeed, my son, without specifying a time period, how long is she required to nurse him in order to fulfill the condition? She is required to nurse the baby for two years from his birth, which is the length of time generally designated for nursing."
And the gemara in Brachot 31b says:
"Additionally, Hannah’s emphasis in speaking to Eli, “for this youth I prayed” (I Samuel 1:27), indicates that she came to protect him from danger. As Rabbi Elazar said: Samuel was one who taught halakha in the presence of his teacher. Hannah wanted to pray that he not be punished by death at the hand of Heaven for his transgression, as it is stated: “And they slaughtered the cow and they brought the youth to Eli” (I Samuel 1:25). This verse is puzzling. Because they slaughtered the cow, therefore, they brought the youth to Eli? What does one have to do with the next? Rather, this is what happened: Eli said to those who brought the offering: Call a priest; he will come and slaughter the offering. Samuel saw them looking for a priest to slaughter the animal. He said to them: Why do you need to look for a priest to slaughter it? Slaughter of an offering performed by a non-priest is valid. They brought him before Eli to clarify his statement. Eli said to him: How do you know this? Samuel said to him: Is it written in the Torah: And the priest shall slaughter indicating that the offering may only be slaughtered by a priest? It is written: “And the priests shall offer,” only from the stage of receiving the blood in the bowls and onward is it a mitzva incumbent upon priests alone. From here the halakha that slaughter by a non-priest is acceptable is derived. Etc"
And this happened right after Shmuel finished nursing, as it says in Shmuel 1:1:24:
"When she had weaned him, she took him up with her, along with three bulls, one ephah of flour, and a jar of wine. And though the boy was still very young, she brought him to the House of the LORD at Shiloh."
The verses brought in the gemara follow this one.