Yeah that happens. More than once I've thrown away a lot of work due to a shift in priorities. The thing to realize is that as an engineer you have very little control here. All you really can do is argue with higher-ups (they likely won't listen) or job hop (you can't do that too often).
It's sort of like making a movie. You start out with more material than what you need for the finished product because sometimes you don't know what's going to work ahead of time. Yeah, it sucks when you project gets left on the cutting room floor, but it happens. There's plenty more work to do. It might sound cynical, but don't get attached.
In terms of a middle ground, I sort of think about business concerns the same way I think about the news. Be aware, but don't worry, because you don't have much control anyway. If something really important comes around, start preparing to do what you can with what little control you do have (job hop, move out of a place that's about to be a war zone, etc). Don't waste your finite time and attention on day-to-day details. Save it for the big stuff.