There is no specific doctrine for this, but I think it can be answered logically with the help of scripture verses and with the doctrine of Immaculate Conception which teaches that Mary was sinless and remained so always.
The question whether Mary knew that she was sinless is hard to know because the question seeks the answer from the perception of person who is defined as sinless. Nevertheless it is possible to infer that she knew about it but possibly didn't know the specific purpose for which it was meant other than just obeying God's command to be so.
Mary was conceived immaculately which meant that at the time of conception she was preserved from the stains of Original Sin. As a consequence of this, the state of original sanctity, innocence, and justice, as opposed to original sin, was conferred upon her, by which gift every stain and fault, all depraved emotions, passions, and debilities, essentially pertaining to original sin, were excluded. But she was not made exempt from the temporal penalties of Adam — from sorrow, bodily infirmities, and death.
With this gift Mary would have no inclination to sin. Being unstained with the original sin of man means that she can also perfectly choose not to sin. She had a perfect will to not sin. A person selected by God would not choose to sin as that doesn't make sense.
Whether she knew that she was sinless:
We can all look back on our own lives and think of at least one sin we committed. In view of her immaculate conception as stated above, Mary couldn't have. Therefore she must have known she was sinless. But assuming our self to be sinless as compared to others and declaring oneself as saint is in itself a sin. So Mary possibly was aware that she was sinless but was humble enough before the Lord and other people in not thinking herself sinless because that was for God to judge. As Jesus said about two Pharisee in Luke 18:14, praying in two different way: one boasting about his righteousness and other accepting that he is a sinner.
Possibly she was not aware of the purpose of her holiness and just thought it to be an obedience to God. She must have been perplexed thinking, why specially angel Gabriel has to come visiting her and declare:
Luke 1:28 And coming in, he said to her, “Greetings, favored one! The Lord is with you.” 1:29 But she was greatly troubled by his words and began to wonder about the meaning of this greeting.
Lord can remain only with sinless beings. She knew that she was sinless but she was thinking why God has to send His special angel to her. As she was not knowing the purpose of her sinlessness, she was surprised with this special appearance of angel Gabriel. Gabriel understood her confusion in mind and declares:
Luke 1:30 So the angel said to her, “Do not be afraid, Mary, for you have found favor with God! 1:31 Listen: You will become pregnant and give birth to a son, and you will name him Jesus. 1:32 He will be great, and will be called the Son of the Most High, and the Lord God will give him the throne of his father David.
And Mary's response was that of blind obedience:another sign of her sinlessness.