You asked: how does the law deal with contractual obligations where the contracting parties change? As you have identified in the comments, the answer has to do with the concept of novation – that is, the formation of a new contract with different parties. The consent of all parties to the original contract is required to replace their rights and obligations with new rights and obligations defined in the novated contract.
The other answers appear to be discussing the concept of assignment. Assignment should not be confused with a change of contracting parties, or a “transfer of contract” (which is not a meaningful concept at common law). It is often possible to unilaterally assign the rights accrued under a contract to a third party, but it is not possible to assign the obligations.
Specifically, the contractual right that can be assigned under New Zealand law is a “thing in action”: section 50 of the Property Law Act 2007. In other common law countries this is still called a chose in action, meaning the right to sue. For most businesses, a chose in action is more like an “invoice” than a “contract.”
If A does work under a contract with B and becomes entitled to payment, this entitlement is a chose in action that can (generally) be unilaterally sold to C. This commonly occurs where C is a debt recovery or factoring business. However, the contract between A and B which says that B must pay A when A does certain work is not a chose in action. It is a relationship that gives rise to a chose in action only when A does the work. Unless the contract is novated, C has no right to do the work and sue on the contract between A and B. This is the doctrine of privity of contract.
If C has nevertheless done the work without a novation, there are two ways that C might get paid. One is for C to sue A, claiming that A subcontracted the work to C. In this situation, from B’s perspective, A is still responsible (and entitled to be paid) for the work. B does not have to pay C, and A is only required to pay C the amount agreed under the subcontract. It could be difficult to argue that a business sale agreement created this kind of subcontract.
The other way is for C to sue B on the basis of the equitable doctrines known as unjust enrichment, quasi-contract or quantum meruit. These doctrines are complicated, but essentially based on the idea although B never agreed to pay C for the work, it would be unfair to allow B to benefit from the work. Again, C may not be entitled to the full amount of money that B agreed to pay A, because its rights are based on the court’s assessment of what equity requires, not the terms of the contract between A and B.