The Church presumes a marriage valid until proven otherwise. In any case, Mary and Joseph married under the Old Covenant. That means that their marriage is considered valid, but it was not sacramental because sacraments were not yet instituted at the time of their marriage. It also means that their marriage was not subject to Church law as the Church did not exist at that point.