I have this philosophy, if they fire me it's good because it was not the right place for me.
It's also been true for me, that if I don't set policy part of my job is to enlighten those who do so they can make the right choice.
When idiotic things occur frequently enough and I cannot do the right thing I don't WANT to waste my time there. Especially when there are others who would appreciate honesty from a well informed viewpoint. And when others don't exist I create my own job. Which is how I've lived for the last number of decades and still do.
One have to be smart about how one executes things of course since the above operational policies, if you want, will easily be costly personally. But if I cannot be honest to those I work with I'm much better off going elsewhere. Most people want to work with decent people and try very hard to find us.
Saying you refuse to implement a faulty solution, and being removed, if you survive it all it can be a blessing in disguise once it goes belly up. You were the one who knew it would fail and tried to warn everyone. Of course if someone in management has another agenda, than the company's best, and if he is trusted well enough by top management, you can easily be fighting an uphill battle where there is no win for you to be had there.
Because of these things I have a personal policy of surrounding myself with able people. Able people know they can produce a proper exchange with society (to make a living) and so don't bother to come up with these unusual solutions which cause a lot of damage to all involved (often criminal solutions). Unlike what some claim there is no criminal gene. You can however be brought up to think that you are nothing and will never amount to anything. That makes it extra hard to believe in yourself and work hard, but is ultimately no excuse.