Depending which country you’re located in, but if it’s Canada or the United States, buying another home has nothing to do with the taxability of the gain on the sale of your principal residence.
Both countries only require that the property you sell be your principal residence. Although they have slightly different rules around what constitutes a principal residence, in a practical sense, they’re pretty much the same.
Canada allows a full exemption from the gain. The US allows an exemption up to $250K per person, once every 2 years. There are complicated exemptions and limitations in some cases, but they apply to relatively few people.
Back prior to 1997, there was a US rule which allowed you to roll over the gain from an old house when you purchased a new house, but that’s been gone a long time.