Because a teenage mother out of wedlock in Israel 2,000 years ago needed a man to belong to, to protect her, to give her legitimacy; because God knew St. Joseph would accept his chosen role and because he loved God and Mary. Any number of reasons for the "charade."
Touching the holy makes one holy it does not desecrate the holiness
Remind Judas Isacriot.
"Because a teenage mother out of wedlock in Israel 2,000 years ago needed a man to belong to, to protect her, to give her legitimacy"
God did not need a charade to cover what He was doing nor a protector for Mary. He was quite capable of bringing His purposes about without creating a ruse to fool the authorities or violating His instructions to husbands and wives.
"Remind Judas Isacriot."
He received the same treatment as Achan. However Judas did not diminish or desecrate the holiness of God, in fact, it shown brighter on the cross.