It is difficult to pinpoint exactly when Jesus knew He was the Son of God (second Person of the Trinity) since it is not clearly stated in the Bible. However in Scripture, it shows that the pre-incarnate (pre-human) Christ always knew He was the Son of God (second Person of the Trinity). In John 8:58, Jesus fully realized who He was “I tell you the truth, Jesus answered, before Abraham was born, I am”. Further on in John 17:5, Jesus says, “And now, Father, glorify me in your presence with the glory I had with you before the world began.”
Even before He came to this world through incarnation (human form), He already knew His role/purpose that He would die for our sins. (Rev. 13:8). Moreover, though we do not have clear Biblical reference revealing the thoughts of Jesus as a baby, we can at least conclude through Scripture that as a young child Jesus was well aware of His role His father has sent Him to accomplish on earth.
In Luke 2:46 – when His parents were concerned about His being mission on a trip to Jerusalem, they found Him in the temple, “sitting in the midst of the teachers, both listening to them and asking them questions.” When confronted, Jesus told His parents “Why were you searching for me?" he asked. "Didn't you know I had to be in my Father's house?"
Even though his parents did not understand Him, Jesus at the age of 12 already understood that He was the Son of God and the Father has foreordained the work He was to do. After the above incident in the temple, we are told that “Jesus grew in wisdom and stature, and in favor with God and men” (Luke 2:52)
If at this point of his life Jesus knew everything, it would not be logical that He would need to “increase in wisdom.” Not only did Jesus have to grow physically (in stature), He also had to put Himself in a position where He needed to take on knowledge as a man. Even though He was and is always God, He also needed to be truly and fully man. (except for sin)
As such He is able to experience things such as temptation and hunger. In order to accomplish this, He emptied Himself from any physical characteristics of divinity and took on a form of a man. Isaiah sums it up nicely when He said, “He grew up before him like a tender shoot, and like a root out of dry ground. He had no beauty or majesty to attract us to him, nothing in his appearance that we should desire him” (Isaiah 53:2).
Summary: From this there is one thing we can we certain of, the pre-incarnate Jesus always knew who He was and what His work in the world was to be. Through Scripture, we can safely conclude that the incarnate Jesus came to that realization at some point in His early life. However if this point was the second when He was born, we cannot be certain.
[Answered by George Mah]