This question seems to be a variant on the question of whether ignorance excuses from sin. In this case: "Does ignorance that the priest's advice is conducive to sin excuse one from sinning by acting on his advice?"
St. Thomas answers the question of whether ignorance excuses from sin in his Summa Theologica I-II q. 76 a. 3 c.:
Ignorance, by its very nature, renders the act which it causes involuntary. Now it has already been stated (Articles [1],2) that ignorance is said to cause the act which the contrary knowledge would have prevented; so that this act, if knowledge were to hand, would be contrary to the will, which is the meaning of the word involuntary. If, however, the knowledge, which is removed by ignorance, would not have prevented the act, on account of the inclination of the will thereto, the lack of this knowledge does not make that man unwilling, but not willing, as stated in Ethic. iii, 1: and such like ignorance which is not the cause of the sinful act, as already stated, since it does not make the act to be involuntary, does not excuse from sin. The same applies to any ignorance that does not cause, but follows or accompanies the sinful act.
On the other hand, ignorance which is the cause of the act, since it makes it to be involuntary, of its very nature excuses from sin, because voluntariness is essential to sin. But it may fail to excuse altogether from sin, and this for two reasons:
on the part of the thing itself which is not known. For ignorance excuses from sin, in so far as something is not known to be a sin. Now it may happen that a person ignores some circumstance of a sin, the knowledge of which circumstance would prevent him from sinning, whether it belong to the substance of the sin, or not; and nevertheless his knowledge is sufficient for him to be aware that the act is sinful; for instance, if a man strike someone, knowing that it is a man (which suffices for it to be sinful) and yet be ignorant of the fact that it is his father, (which is a circumstance constituting another species of sin); or, suppose that he is unaware that this man will defend himself and strike him back, and that if he had known this, he would not have struck him (which does not affect the sinfulness of the act). Wherefore, though this man sins through ignorance, yet he is not altogether excused, because, not withstanding, he has knowledge of the sin.
this may happen on the part of the ignorance itself, because, to wit, this ignorance is voluntary, either directly, as when a man wishes of set purpose to be ignorant of certain things that he may sin the more freely; or indirectly, as when a man, through stress of work or other occupations, neglects to acquire the knowledge which would restrain him from sin. For such like negligence renders the ignorance itself voluntary and sinful, provided it be about matters one is bound and able to know. Consequently this ignorance does not altogether excuse from sin. If, however, the ignorance be such as to be entirely involuntary, either through being invincible, or through being of matters one is not bound to know, then such like ignorance excuses from sin altogether.
So, a person asking a priest who is known to permit or advise adultery, for example, is "as when a man wishes of set purpose to be ignorant of certain things"—e.g., of how a more faithful priest would advise him. This person would sin in following the unfaithful priest's advice.
But it is a different situation if the person learns what he can about his situation, consults several priests, etc., and acts on the lawful knowledge and advice he obtained from the priests.
Also,
Acts 5:29: "We ought to obey God rather than men."
cf. St. Thomas Aquinas's question "Whether subjects are bound to obey their superiors in all things?" (Summa Theologica II-II q. 104 a. 5)
Pope Leo XIII's encyclical Libertas:
- …where the power to command is wanting, or where a law is enacted contrary to reason, or to the eternal law, or to some ordinance of God, obedience is unlawful, lest, while obeying man, we become disobedient to God.
and his encyclical Diuturnum:
- The one only reason which men have for not obeying is when anything is demanded of them which is openly repugnant to the natural or the divine law, for it is equally unlawful to command to do anything in which the law of nature or the will of God is violated. If, therefore, it should happen to any one to be compelled to prefer one or the other, viz., to disregard either the commands of God or those of rulers, he must obey Jesus Christ, who commands us to "give to Caesar the things that are Caesar's, and to God the things that are God's," [Matt. 22:21.] and must reply courageously after the example of the Apostles: "We ought to obey God rather than men." [Acts 5:29] And yet there is no reason why those who so behave themselves should be accused of refusing obedience; for, if the will of rulers is opposed to the will and the laws of God, they themselves exceed the bounds of their own power and pervert justice; nor can their authority then be valid, which, when there is no justice, is null.
If one seriously does not know his priest's or other superior's command or "pastoral advice" is unlawful, "contrary to reason, or to the eternal law, or to some ordinance of God," then the superior will be more at fault.