Take the Iraq war. The goal was to further assert ourselves in the Middle East, settle old scores, signal to our official enemies we mean business and enrich a bunch of military contravtors.
But the rationalization that I think made it possible for a lot of these people to sleep at night was things like defending the country, empowering women, bringing in democracy etc.
These are different things.
Also, as an aside, I may be wrong on this, but I think people sometimes underestimate the foothold of the CCP in mainland China and assume a coup would happen a week after YouTube was let in.
I feel this is incredibly naive; I mean if you look at how in our democratic societies narratives are regularly constructed to strengthen the status quo, often by pretending that the 2 parties actually have major principled disagreements, while nothing fundamentally changes almost no matter who gets elected, to the point where there are studies showing that the majority of policies people in the U.S. are in favor of don't get enacted.
Hong Kong is a bit different, because people there don't necessarily see themselves as having that much in common with mainland Chinese, but I don't think CCP would actually collapse if YouTube and Twitter were to be let in.
I happen to think the bans have more to do with wanting to empower local companies, (which yes are more easily controllable too), so that there's a strong internal economy that would ultimately be able to withstand sanctions etc.