And why did Joseph take her as his wife even when he knew that her babe was not his? So God could pull a fast one on the watching community, that her babe would not be identified as a bastard for lack of a husband, or that her babe was not of fornication with Joseph before the year-long pre-nuptial betrothal had passed according to the custom of insuring that she was a virgin at the formal consummation?
No. God does not play lying games.
Joseph married Mary in order that Jesus could be counted as David's legitimate royal heir, though Joseph refrained while that time of proof of her virginity right up to the babes birth passed, and all could witness thereto.
You'd better think out what all this means, particularly in view of the cultural context.
Sorry, guys — the keyboard made me do it (double post) — mea apologea