I don’t know if the immune system could be trained that way, but it’s an interesting idea. Unfortunately one issue I can think of is that the same period you describe is both formative for the immune system (good for our purposes) and also the period of rapid growth of the brain (not so good). Even if the immune system could be trained during that time, the electrodes would still move relative to their intended targets.
There’s also the issue a lot of these surgeries involve feedback from a conscious patient, and that’s obviously impossible with a newborn.