> It wasn’t rational for him to force his way onto Hong Kong
When that happened, Hong Kong was involved in ongoing riots and people were proclaiming (Hong Kong) independence on the streets for months. The legislature was stormed in an event that was not unlike Jan 6 Capitol Hill in the US (we sure did feel the awkward resemblance of the two events...)
Everyone can have their views on whether suppressing the riots was morally justified, but Xi had to do something to assert the CCP's sovereignty over Hong Kong. It was the only rational move unless they were prepared to give up Hong Kong.
> the territory would automatically become China in a few decades
Not sure which place you're talking about. Hong Kong is already part of China at least since the 1997 handover. And Taiwan will never become under CCP rule if status quo is preserved. Don't think there's any mechanism for "automatically" taking over Taiwan.
I don't know how familiar you are with the history, but long-term thinking and patience was essentially the reason China was able to gain back control Hong Kong from the Brits, pretty much on China's terms. They took advantage of the 99-year lease on the New Territories, waited until the Brits started developing on the leased (as opposed to ceded) land, and caught them with their pants down when they realized they had no feasible plan to partially hand back the territory when the lease expired.
Hong Kong has always been a template (in the CCP's mind at least) for taking back Taiwan, I don't know how you'd come to the conclusion that they would forego long term potential for short term gains. It's like you're talking as if they already invaded Taiwan and you're shaking your head over the stupidity of it. (No, it hasn't happened yet.)
The threat of course always seem real enough. It's all a game of chicken. The one who seems most crazy wins. Back then during the 1970s, China also threatened to invade Hong Kong if the Brits didn't hand it back to them. They want you to think the leadership is irrational. Makes them harder to predict.