This should never happen. If it happens, the behavior is undefined, i.e., network may not work in a number of ways.
IP addresses are hierarchical and must be assigned hierarchically. All IP addresses are divided between 5 regional organizations (e.g., RIPE in Europe). These organizations give subblocks of their addresses to large-scale internet providers. They in turn can give subblocks to smaller providers, and so on. At each step is must be ensured that the subblocks don't overlap.
If B has a network 123.123/16 than it is B's responsibility to ensure that addresses within its network do not overlap. For A to get the network 123.123.123/24 it has to get it through B (does not have to be directly). Then B knows that it can't assign addresses in 123.123.123/24 to anybody, because this block is now owned by A.
As was said in different answers, private IP addresses (i.e., specific blocks marked for private addresses) can be reused. It is a responsibility of each organization to ensure that these addresses are not routed outside this organization.