Sacraments such as baptism, confirmation, marriage and Holy Orders are NOT automatically invalidated by the recepient being in a state of mortal sin, though they do not become fully operative until such time as the person confesses their mortal sin.
Yes, things such as not being open to children at the time of marriage will invalidate it, however that only becomes a mortal sin after one makes the vows which include promises to be open to life etc … I don’t think the OP is talking about mortal sins that happen during or after the ceremony.
You’ll never find the Church repeating the process of confirming or ordinaining someone, for example, just because they happened to be in mortal sin at the time they received the sacrament. Although they may do so for other reasons.
Same goes for marriages - notice that in an annulment process no-one ever gets asked if they were in a state of mortal sin at the time of marriage, because it doesn’t invalidate the sacrament if they are. If it DID invalidate marriages, they’d ask because a heck of a lot more of 'em could be annulled if it did!
Yes, if you were in a state of unconfessed mortal sin and received the sacrament it may have constituted sacrilege - depending upon whether you knew at the time that it was a grave sin to do so.