In light of Joseph being called a righteous man in Matthew 1:19, does this mean that divorce because one of the two was not a virgin at the time of marriage is biblically valid?
Two possible answers:
So I don't think this passage tells us anything about virginity as a grounds for divorce. It seems to be about breaking off a betrothal rather than divorce proper. And even if it is about divorce proper, Joseph had good reason to suspect unfaithfulness since the engagement or marriage or relationship had begun, while a mere lack of virginity might long predate you having ever met your marital partner.
If a person had falsely presented themselves as a virgin and you married them, that might be valid grounds for divorce. But if they never presented themselves as such (either through openly admitting such a previous sexual relationship, or if they never said but you never asked), then I don't see how that is any better grounds for divorce than simply "I'm tired of you" or "I found someone who I think is better"
I know of no doctrine held by any Christian tradition based on this passages that speaks to virginity at the time of marriage in relation to possible divorce. It is simply not the subject matter of the passage and drawing such a conclusion from it would be bad hermeneutics. You would need to find other teachings on previous relationships or extra-marital relationships in order to address that issue in a Biblical fashion.
If you look at other Biblical passages, you will note that basically the only valid grounds for divorce is the case of adultery. Even then it is not prescribed / required, only possible allowed.
If you look into the marriage traditions of the time, you will find that the issue of divorce was as relevant to Betrothal (engagement of sorts) as it was to marriage. A betrothal could not just be broken off for any reason, it was as good as a marriage vow as far as being binding on the parties, but the relationship was not to be consummated until after the wedding.
Mary getting pregnant during the betrothal was (barring the supernatural) obvious proof of adultery. Having committed herself to marry and be faithful to one man and entering a binding contract with him, Joseph would know he hadn't slept with her so she must have slept with another man.
With this understanding, we see that the only thing this passage could teach us about divorce is to reinforce the teaching that says adultery is possible grounds for divorce, but that it is not unlawful to NOT divorce even cases of adultery.
This is a good question. Joseph and Mary had entered into the covenant of betrothal for marriage. The terms of that covenant were that each would maintain purity until their wedding. When it was found that Mary was pregnant, Joseph knew quite well that the child was not his. The conclusion was that Mary had been unfaithful to him, even though this turned out to be an invalid conclusion.
So, the issue was that Mary was thought to have broken the covenant of marriage by being unfaithful--not necessarily that she was no longer a virgin. Indeed, Boaz married Ruth, who had already been the wife of another. David married Bathsheba, who had been the wife of Urriah.
So, again, virginity was not the issue per se, but unfaithfulness was.