Did Mary know she was sinless, according to Roman Catholic teaching? The Roman Catholic Church teaches the Immaculate Conception that asserts Mary was conceived without sin and remained sinless for her entire life.  

Assuming this to be true, did Mary know that she was, in fact, sinless, while everyone else was not?  It seems that this would have been obvious.  If so, it seems should would probably have expected that God had already selected her for a special purpose.  However, she sounds surprised at the angel greets her as a "favored one":


  Now in the sixth month the angel Gabriel was sent from God to a city in Galilee called Nazareth, 27 to a virgin engaged to a man whose name was Joseph, of the descendants of David; and the virgin’s name was Mary. 28 And coming in, he said to her, “Greetings, favored one! The Lord is with you.” 29 But she was very perplexed at this statement, and kept pondering what kind of salutation this was.  Luke 1:26-29 NASB


So, again, my question is, according to Roman Catholic doctrine, did Mary always know that she was sinless?  Or did she come to know that later at some point?  If she knew she was sinless, did she realize earlier that she had been set aside for a special purpose?
Did Mary realize that she was sinless before the Annunciation?

No. If I cannot remember my sins, the only reasonable conclusion is that I forgot my sins, or that I was ignorant of having sinned, not that I was without sin. The same is true of Mary. She could not have known that her life so far had been free of sin, even if she could not remember any sins. (Furthermore, the doctrine that Mary was without sin applies to Mary's entire life, including the unknown future.)

So it would certainly not have been obvious that she was free of sin, and she would not have expected that God had selected her for the purpose in question. That was the very point of the greeting and the Annunciation: to inform Mary of something that she could not have known without revelation. 

Did others realize that Mary was sinless?  

It is impossible for others to realize this based on a person's actions. To have never sinned is something far beyond having lived a righteous life. Many sins are internal and therefore hidden, and many actions that seem sinful might be good. Those who knew Mary would have thought very well of her, but without divine revelation they could not have considered her to be without sin. 

Why did Mary react as she did to the greeting?


The greeting was spoken by Gabriel, an angel. Clearly, it was very serious.
Gabriel calls her by the name "kecharitoméne", which means "full of grace" (Redemptoris Mater 8), and not by her proper earthly name, "Mary". Naming a person in this way is common even today (Smith, Baker, Sawyer...), and it was certainly common in the Bible (Abram, Abraham, Sarah, Jacob...). However, Mary is troubled by this particular name. She understands the language, so she knows what was meant. She did not ask for clarification of why she was being called by this name (as she did when the Angel revealed that she would conceive, though she was and planned to remain a virgin). Still, the name did weigh very heavily upon her.
Mary had great humility. When Catholics say the Rosary with the Joyful Mysteries in mind, when the Annunciation is remembered, the prayer is "for the love of humility"). When a humble person is told that she is favored, she typically reacts with genuine surprise and perhaps confusion, because she has not until that point been imagining herself as favored. Most people might be very happy to be told that they are favored by anyone, but Mary just begins to think deeply about what God's message means.


Did it never occur to Mary, at any point in her life, that she was free of sin?

She could only come to have such a belief as a direct result of divinely-revealed knowledge, which may have included the revelation that she was the Mother of God (she was very much aware of this). Even then, she would have been aware of such knowledge only after the Annunciation (see the first question). Furthermore, there is no Church teaching (that I have been able to find) that suggests that the thought "I am sinless" had occurred to Mary. She does not dwell on attempting to recall past sins, and instead seems to spend much of her time contemplating what God is telling her.