I've occasionally rationalised this on the basis that I'd rather China knew everything about me than the US on the basis that I visit the US once every few years and am relatively unlikely to visit China.
https://foreignpolicy.com/2018/03/29/the-disappeared-china-r...
Their main claim to legality is sufficiently questionable that they legislated to deny officers of the International Criminal Court entry to the USA:
https://en.wikipedia.org/wiki/United_States_and_the_Internat...