Is it that each ATC is assigned a group of codes, for IFR and for VFR traffic? So they allocate you whichever of those available is considered most suitable.
The local code assigned to circuit aircraft is different from the one for off-circuit VFR traffic. IFR get their own personal (discrete) squawk. When going to a different service, I either get one of their squawks, or am told to use 7000.