That depends on your understanding of the word “sustain”.
The 1828 Webster’s dictionary gives the following definition:
SUSTA’IN, v.t. [L. sustineo; sub and teneo, to hold under.]
1. To bear; to uphold; to support; as, a foundation sustains the superstructure; pillars sustain an edifice; a beast sustains a load.
If you can support (and if your conscience can tolerate) the policy decisions of the Presidency and other leaders, than you can uphold them with your faith and prayers, and exercise the spiritual maxim: “Do unto others as you would have them do unto you” (see 3 Nephi 14:11). There is no risk of offending God under such circumstances. You should be safe in answering the relevant LDS temple recommend question(s) affirmatively with such an understanding. Sustaining is more than just praying for our leaders, or even praying for our enemies; it also implies supporting them with your faith and effort. Such effort can include admonishing them in their faults (see D&C 6:19 and D&C 112:12), as well as moving a program forward on the ground level or wherever you may be serving. Constructively criticizing faulty policies is also a form of support, and is different than slander, or evil speaking. There may be a time when you would feel comfortable praying for someone, but not comfortable sustaining or supporting their behavior or leadership. Therefore, the distinction is important.
However, if your understanding of sustain includes “following the prophet”, no questions asked, then you are violating the first and second commandments to have no other God beside the Lord, and to not worship idols. See our post here. This was the circumstance that King Noah’s people found themselves in: “Yea, and they also became idolatrous, because they were deceived by the vain and flattering words of the king and priests; for they did speak flattering things unto them” (Mosiah 11:7). Abinadi was sent by God to ask the leaders why they hadn’t taught the people the commandments, especially the first two commandments which they had a particular problem with (see Mosiah 12:31-37).
D&C 59:21 says it clearly: “And in nothing doth man offend God, or against none is his wrath kindled, save those who confess not his hand in all things, and obey not his commandments.”
Another of the Lord’s commandments he says he expects to be obeyed in pertains to who is worthy to be baptized. If you understand your baptism to be dependent upon whether or not you sustain any leader, than you are against the Lord when he declares his doctrine and baptism as only requiring faith in Him and repentance (3 Nephi 11:31-40). Sustaining is a separate function, and should only be used as a benefit to the leaders to help them see when they have the support of the people or not. An unbiased version of a sustaining vote should be welcomed by the leaders so as to help them combat their own weaknesses and foibles. In no way should a convert be withheld from being baptized a member of Christ’s church, or a member be withheld from entering the temple, for simply declining to uphold a leader with whom they have a difference of opinion with. Such priestcraft and bullying only produces forced compliance. In stark contrast to such policies, the scriptures vehemently proclaim: “No power or influence can or ought to be maintained by virtue of the priesthood” (D&C 121:41).
And certainly, as the Prophet Mormon attests, there is a time when sustaining those who are grossly wicked will garner you the disapproval of an offended God:
And now, my son, I dwell no longer upon this horrible scene. Behold, thou knowest the wickedness of this people; thou knowest that they are without principle, and past feeling; and their wickedness doth exceed that of the Lamanites.
Behold, my son, I cannot recommend them unto God lest he should smite me. (Moroni 9:20-21)
Such cases should be self-evident, but as we have seen with King Noah and his people, and as it is the “nature and disposition of almost all men, as soon as they get a little authority, as they suppose, [that] they will immediately begin to exercise unrighteous dominion” (D&C 121:39), it is unfortunately very easy to be “blinded by the subtle craftiness of men” (D&C 123:12).