After Allah, the Exalted, mentioned the story of Zakariyya, and that He blessed him with a righteous, purified and blessed child even in his old age while his wife was barren, He then mentions the story of Maryam. Allah informs of His granting her a child named `Isa without a father being involved (in her pregnancy). Between these two stories there is an appropriate and similar relationship. Due to their closeness in meaning, Allah mentioned them here together, as well as in Surahs Al `Imran and Al-Anbiya'. Allah has mentioned these stories to show His servants His ability, the might of His authority and that He has power over all things. Allah says,
إِنِّي أَعُوذُ بِالرَّحْمَـٰنِ مِنكَ seek refuge of the Rahman (All-Merciful), against you." (19:18) Some reports have it that when Sayyidna Jibra'il (علیہ السلام) heard these words he retreated a little in reverence of Allah's name.
إِن كُنتَ تَقِيًّا
"If you are God-fearing." - 19:18.
These are the words which a helpless person would utter to a cruel oppressor begging him that if he is a believer then he should desist from tormenting him. The intention is that Sayyidah Maryam (علیہا السلام) entreated Sayyidna Jibra'il (علیہ السلام) who stood before her in the guise of a man, that he should fear Allah and abstain from evil deeds. In short, the expressionإِن كُنتَ تَقِيًّا (if you are God-fearing - 19:18) is not a precondition for seeking the protection of Allah but a condition to make her prayer more effective and inducing. Some other commentators have said that this expression is used for emphasis, meaning that even if you fear Allah I seek His protection; and if the position is otherwise then I shall seek Allah's refuge with added vehemence. (Mazhari)
Tazkirul Quran
Maulana Wahiduddin KhanOn ayahs 15–20
It is said that once during John’s childhood, some children asked him to come and play with them. He refused and said, ‘We have not been created for this.’ This shows that from his very childhood he was conscious that life should be purposeful. Sensitive by nature and possessed of a feeling heart, he was free of psychological complexes. He scrupulously fulfilled his duties to his parents and was completely devoid of arrogance or willfulness. These are the qualities that give man the ability never to diverge from the path of God’s Book. It is the possessor of such qualities who is showered with God’s mercy in this world and in the life hereafter.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.