The story of the birth of prince Siddhartha tells us that he walked and talked right after birth. That he even said that he will become a Buddha in this life and end the cycle of life. But after this he seems to have forgotten what he knew about being a Buddha even on the day he left the palace to find the truth. He started off knowing he would become Buddha, then becomes very confused with all the life experiences as a prince and has no idea what to do or that becoming a Buddha is the answer to it. How is this possible? Is it a flaw in the story or is my understanding of the question poor?
Prince Siddhartha was insulated from anything that might prompt him from renouncing the householder's life. Not being fully liberate at that point the natural tendency of the mind is to enjoy such experiences. There is no record where he forgot such fate but I would presume that he would have expected to be a Universal Monarch as this is what would have been feed to him constantly. Maha Saccaka Sutta mensions that
Then, Aggi,vessana, I thought thus, ‘I recall that when my father the Sakya was occupied while I was sitting in the cool shade of a rose-apple tree, quite secluded from sensual pleasures, secluded from unwholesome states, I entered upon and abided in the first dhyana that is accompanied by initial application and sustained application, zest and joy born of seclusion.
perhaps there could be some forgetting or setting aside. But when he left the palace I would expect he would have expected to be a Buddha otherwise he would not have followed through in renouncing to find the truth.
This is the Buddhist equivalent of "Why did Joseph have to go to his ancestral homeland for a census, even though it makes no sense and flies in the face of everything we know about the Roman census?" or "Why do some of the gospels trace Jesus's ancestry back to King David through Joseph, when Joseph was in no way involved in the conception of Jesus?"
In all 3 cases, the answer is: Because it's obviously bullshit, added after the fact to make the Founder seem more divine and impressive. You can rationalize and cherry-pick if you want, and come up with a story that sort of works, but there's no need: newborn infants don't talk, and the historical Buddha likely had no idea as a child what he was going to do in adulthood. Assertions to the contrary in an ancient text that wasn't written down until hundreds of years after the event can be safely disregarded.
In general, separating the historical facts of the Buddha's time from the legends that grew up afterward is very difficult, although Stephen Batchelor has spent a lot of time trying to parse this out (in Confessions of a Buddhist Atheist and After Buddhism).