It is a common glitch with Codsworth. It really doesn't have anything to do with much else than being really buggy in the vanilla when trying to get him assigned. Vanilla, modded, or both.
After 5000hours all I can say is in some saves "he is better - sometimes not" when it comes to his assignments.
I will say I have had better luck with him in two ways.
Use AFT on him.
Wait until later in the game and his "funky-AI" seems to clear up a bit and assigning him seems to work better.
Lastly, trying too many of the standard AI console commands on him or other companions / glitched NPC' like the vault-tec rep / level 4 merchants only makes it worse.
I just wait a bit between trying and have near 100% success in eventually getting them to do what I want - where I want it.
"hahaha, just not when I want them to do it."