Did they understand that Jesus was God?
Well for Mary, being told He (Jesus - God who saves) was going to save His people. And since the birth of Christ was like no other in the history of the world (a light of revelation to the gentiles), and none like those among His own people ever born (who came to save Israel.) I’d say Mary knew. In fact she stated and recounted to Elizabeth saying, “God my savior.” Which is what Jesus means. She also stated that God saved her, the name of Jesus transcribed on her soul. The Angel also said to Mary, “The Lord is with you”, "full of grace.’,“highly favored.” “He will overshadow you.” Mary couldn’t err that the Messiah was God’s Son to save souls - Jesus. Saint Joseph was a discerning man: “Do not be afraid to take Mary as your wife.” The Angel also told Joseph to bring Mary and Jesus outside of the area wherefore Herod sought Christ during the bloodshed of the Holy Innocence.
But if anyone doubts whether Joseph knew Jesus was God or not. I’d say that became clear when he and Mary found Jesus in the temple. Where for some reason I see this smile on His (Jesus) face - in a way not to spite them. But when Mary and Joseph found him in the Temple, “Did you not know I am in my father’s house?” And Mary asked, “Why do you do this to us?” Then again later on, at the Wedding Feast of Cana, Mary told Him they were out of wine. And He said, “Woman (i.e. like God saying that to Eve) what does this have to do with me? My hour has not yet come.” She turned to the servants and said, “Do all that/what He tells you.” Interestingly, we don’t read a word of Jesus telling them to get the water for washing feet. So just as the dialogue wherefore Mary asked, “Why do you do this to us?” And Jesus (again, God who saves) was silent and went back with them to their home. In other words, she was asking what was the purpose. And Jesus demonstrated then, and at the Wedding Feast “my hour has not come”, that He is the Son of the Living God. He was in His father’s home. Remember, she kept all these things in her heart. Even what Simeon had stated when the infant was taken (the Presentation): a sword shall pierce your heart. She knew all the time. Mary is the most patient and Holy woman ever. I mean, a woman who knew her Son was going to be killed: “Why do you do this to us?” I mean in heart she was always questioning and contemplating. Each moment of the way, the poor woman expecting the Christ child. Having to leave her homeland. And Saint Joseph moving her around. I mean it wasn’t like traveling this day and age at all. That woman was so blessed. I man truly blessed. From Jesus birth to His death. To the Resurrection. And to the upper rooms. I never seen in the Gospel Jesus visited Mary after the Resurrection. She was there at the tongue of flames. But no word of her seeing her Son rising from the dead. Yet, she was there at the Cross; where she wept over her Son. That baby from the time as an infant she raised, searched diligently with Saint Joseph, finding Him in the Temple. And this woman had to hear these words from Simeon. And at the Wedding Feast at Cana.