That should not happen. If a summary field is not on the layout, it won't summarize. And you should get the same behavior via scripted or manual layout change.
Perhaps there is some detail in your script other than the go to layout step that is involved.
Note that go to layout is notorious for tripping any number of script triggers that might then perform other scripts while pausing the current script. But a manual change in layouts will usually trip the same triggers...