Allah gives the example of Maryam (as), mother of Prophet 'Isa (as), as a servant devoted only to Him. Before she was born, Maryam (as) was dedicated to Allah by her mother with prayers that she would be a good servant and free from all worldly attachments:
Remember when the wife of 'Imran said, "My Lord, I have pledged to You what is in my womb, devoting it to Your service. Please accept my prayer. You are the All-Hearing, the All-Knowing." (Surah Al 'Imran, 35)
Other verses in the Qur'an, show that Allah accepted her mother's prayer about Maryam (as). We are told that she was morally pure and virtuous:
Her Lord accepted her with approval and made her grow in health and beauty… (Surah Al 'Imran, 37)
Allah chose her and gave her great honor:
And when the angels said, "Maryam, Allah has chosen you and purified you. He has chosen you over all other women." (Surah Al 'Imran, 42)
Moreover, we are told that Allah commanded her to be sincerely submissive and obedient to Him.
[The angels said,] "Maryam, obey your Lord and prostrate and bow with those who bow." (Surah Al 'Imran, 43)
At a certain point in her life, Maryam (as) left her family and moved east.
Mention Maryam in the Book, how she withdrew from her people to an eastern place. (Surah Maryam, 16)
There she lived alone and received the marvelous message of the birth of Prophet 'Isa (as). This good news was brought to her by Jibrail.
When the angels said, "Maryam, your Lord gives you good news of a Word from Him. His name is the Messiah, Isa, son of Maryam, of high esteem in this world and the Hereafter, and one of those brought near." (Surah Al 'Imran, 45)
By a miracle from Allah, Maryam (as) became pregnant untouched by any man and gave birth to Prophet 'Isa (as) in a remote place. (Surah Maryam, 20) Maryam (as) humbly accepted the fate that Allah had prepared for her and, after the birth, trusted in Allah and took refuge in Him against all the accusations of the people. The people did not understand all the miraculous events that preceded and followed the birth of Prophet 'Isa (as), and the Qur'an tells us about the hurtful calumny directed against her.
She brought him to her people, carrying him. They said, "Maryam! You have done an unthinkable thing! Sister of Harun, your father was not an evil man, nor was your mother an unchaste woman!" (Surah Maryam, 27-28)
Another verse tells us that the people rejected Allah and brought many false accusations against Maryam (as):
And [We punished them] on account of their disbelief, and their utterance of a monstrous slander against Maryam. (Surat an-Nisa', 156)
When Allah wanted Maryam (as) to take Prophet 'Isa (as) and return to her people; without any concern for what they might think about her or the accusations they would make, she obeyed His command. Even though she found herself in a situation difficult to explain, she did exactly what was expected of her. She reacted to the accusations against her as becomes a Muslim. By obeying Allah's command and being unconcerned about what people thought of her, she showed her moral character to be quite different from those ignorant people who disregarded Allah and made deities out of their fellow men.
With these examples in the Qur'an from the life of Maryam (as), Allah has given us an important message. Maryam (as) was tested in this world with wondrous events. In a very difficult environment that demanded a lot of patience, she endured the onslaught of others' accusations. As a result of all this, Allah made Prophet 'Isa (as) speak while he was still in the cradle and clear his mother of all the accusations against her.
Just like Maryam (as), everyone sincerely attached to Allah is under His protection. Whatever people may say or think about him, a person who practices the morality of the Qur'an is not concerned, because just as in the case of Maryam (as), the important thing is where he stands in the sight of Allah.