There's a lot that could be going on. Codsworth is screwy.
Is he remaining at the spot where you first meet him? He will stay there, if not in service as a companion, until the Quincey Five get to Sanctuary.
It's never been clear cut to me how you get him to actually count in the population count in the first place. When you first get control over Sanctuary he doesn't count towards the population.
Whenever I dismiss him, I usually just cancel out of the "send to menu" instead of actually selecting a destination. This seems to maintain his not being counted in the population. I don't know if actually choosing Sanctuary or another settlement is what triggers his actually getting counted.
In the game I'm currently playing, however, I've never used Codsworth as a companion (and Out of Time is completed), but I managed to get him to both Hangman's Alley and Mechanist's Lair via the assign leader feature of the CP desk at each settlement. He has never counted towards the population of any of these settlements in this playthru.
The only job I've ever seen Codsworth stick with is a vanilla provisioner route after Out of Time is finished. You can assign him to provisioner route before then, but he'll stay in front of the Sole Survivor House with a pack brahmin. I used to send him from Sanctuary to Murkwater as a special vanilla provisioner even though I was also using IDEK's Supply Routes just to get rid of him and actually keep him busy. He certainly doesn't seem to stay assigned to the CP desk.
Anyways, I hope your problem is just a matter of quest progression. If not, I hope bigger brains chime in.