In the OT, they were required to marry within their own tribe. I don't know if Mary and Joseph were of the same tribe or not.
Don't know how to fit it all together.