The doctrine of Mary’s perpetual virginity comes not only from Catholics as you mentioned but from traditional Lutheranism as well. The basis for this is not only an ancient understanding of the role Mary plays in the incarnation, but also it is revealed to the early Christians, especially those coming from Rabbinic Judaism, as a completion of God’s plan as revealed by recapitulating the old testament as it pertains to the Ark Of the Covenant and Mary, as the New Ark of the New Covenant.
The Old Ark of the Covenant which carried the Rod of Aaron, the Manna, and the Word of God, is a foreshadow of the Ark to come which is Mary who also carried these things in their perfection, Christ Jesus our Lord. This method of using scripture from the Old Testament is called “Typology” a practice used also by the apostles in their Epistles to bring forth truths in the OT as it is made manifest in the New, perfected and completed in Christ. Examples of Typology used by the NT Scripture writers and indeed Christ himself are:
Romans 5:16, John 3:14, Mat 24:37-39, 1 Cor 10:1-5 Just to list a few.
This method of using past scripture to show God revealing himself in later times was also used by David foreshadowing Christ as well as other prophets to many to mention. PS 110:4, Zach 6:12-13 again just a few.
This pattern continues even today inside many Protestant Denominations.
When we look at how the Ark of Gods, word, his Bread and the staff of his priest hood, were cared for, we see how The Ark was cherished and held above all things as most sacred to the Jews. Indeed it was considered the Holy of Hollies, the dwelling place of God where the spirit of God dwelt in the form of Pillar of cloud by day and a Pillar of fire by night. Exodus as well as Numbers and Leviticus (many examples).
The idea, that the Ark of the Old Testament, which carried something precious to the Jewish people, would be less important than that, which was carried by the New Ark (Mary), never crossed the mind of early Christians including many of the heretics of the 15th century. It was clear to those men and to all who understood Mary’s role in carrying the Son of God that she was the consummation of what was foreshadowed by the Ark of the Covenant.
Joseph, regardless of what many later Protestants claim, knew to that which Mary was called, and informed by God himself, knew also that which Mary was to carry in her womb. Knowing this, being guided to protect and act as the adopted father of Christ, would he knowing full well to whom Christ was and knowing how Mary had been set apart by God Himself as the “Woman” of whom the prophets spoke of to deliver the Messiah, Ever even for a moment, consider violating her sacred role? One would only have to look to Uzzah (2 Sam 6:10), to see that this coarse of action would be unwise.
From the moment of his conception to the moment of his death, Mary was and continued to be, ever virgin. Set apart from all others, Holy and blessed among women, consecrated to God for his purpose predestined before creation, kept Sacred to the Glory of the Father and the Son and the Holy Spirit, to raise and love Jesus Christ our Lord in perfection.