Like someone mentioned below, it's unrealistic to expect people to think about second or third or nth order effects of their job. Heck, those effects are not even visible in 90% of cases.
To answer your question, the engineer at meta is just building a graph database. It takes a `void* node_data` as argument. Another is just building a kafka-clickhouse data pipeline that can transfer so many millions of `void* message`s a minute. The android engineer is just improving the percentage of requests without location data by using wifi ssids as fallback. The CEO just sees "advertising revenue WoW" in his dashboard. And so on. That it is actually being used for spying is many steps away from each of them -- OK, in the case of meta I'm sure the employees know to an extent. But it's still very different from the feeling they would get if they were doing the end-to-end task themselves.
It's the same thing with other questionable products. It's split up sufficiently across the supply chain that no one is actually aware enough of the task end-to-end.
In some cases, the same participant in the supply chain will be a supplier for something really good and necessary..but they will also be a supplier for something despicable. In this case, it is easy for everyone involved to sweep the latter under the rug.
As far as I have thought about it, there is no way to get rid of this larger problem without also losing the (unfathomably massive) benefits.