That depends. If a priest / bishop deliberately botched the words of consecration at Mass or the essential form of an ordination, and no one heard it, then the individual would have to confess, which is unlikely if it had been done deliberately. But that's why most of the Sacraments require (under normal circuмstances) for there to be witnesses, and which the Church requires 2 co-consecrators for bishops.
But absent a butchery of the essential form, if +Lienart or some other Masonic infiltrator performed the Rite of the Church, it was valid. Period. No amount of internal mental "I don't intend this consecration to be valid." would undo that. There's never been any requirement for the minister to intend what the Church intends or to intend the Sacramental effect. He simply must intend to perform the Church's Rite.
If I'm a priest to show up for 9AM Mass and perform the cermony (correctly pronouncing the essential form), I'm acting as a minister of the Church and intending to do what the Church does. Valid Mass. Period.
Someone trying mental gymnastics is very similar to the contrary-intention stuff in my analogy. I hold a loaded gun up to someone's head and pull the trigger. I could in my mind schizophrenically say "I don't intend for this man to die." but by pulling the trigger I intended to do what is necessary to kill the man, and the man would in fact end up dead, and i intended for him to die by intending to pull the trigger. It's as simple as that.
Sorry, but you are incorrect. The intention is always presumed *unless* the minister of the sacrament states,
in the external forum, that he didn’t have the proper intention when he preformed the sacrament:
“The minister of the sacrament acts in the person of the whole Church, whose minister he is, and in the words which he utters the intention of the Church is expressed. This intention suffices for the perfection of the sacrament unless the contrary is externally expressed on the part of the minister or the recipient of the sacrament.” --- ST III, Q. 64, Art. 8, ad. 2. (Saint Thomas Aquinas)
“Defect of intention must be very rare, with the sole exception of marriage, in which diverse motives may operate to cause defect of real will. There is always an abstract possibility that a man or woman may merely simulate marriage consent. In spite of this, people do not generally worry about the validity of their marriages; the presumption is always that the internal mind corresponds to the words spoken. So it is, likewise, with all the sacraments; the presumption always is that the minister intends what he does.” (pp.491-492, no.567) --- Leeming, Bernard, S.J. Principles of Sacramental Theology. 1956.
“The ‘implicit intention of doing what Christ instituted' means so vague and small a thing that one can hardly help having it — unless one deliberately excludes it.” (p.94) --- Fortescue, Adrian, D.D.. The Greek Fathers. 1908.