In 1997 the 99 year lease on the better part of HK expired, but instead of returning it to a western capitalist ally the Brits gave it to the communists, why?
Though I'm sure there's more to say, you may be [interested in this question] (https://www.reddit.com/r/AskHistorians/comments/d1mltw/why_did_britain_give_hong_kong_to_china/) from last year when u/LordZarasophos and I looked at this.
TL, DR: They had recognised the PRC as the legitimate government of China decades earlier, had no reason to try and keep the city out of Beijing's hands and had no capacity to keep the city (or transfer it to Taiwanese control.)
Taiwan does not come up in that thread, but it's fair to say that much of the same reasoning applies: they couldn't hold the city, and the very act of trying to occupy it would start a war they did not want.