Agree with Dave -cold solder joint or loose wire.
Also it could be a loose e-unit lever had one postwar loco with that problem going about half way around 4x8 layout the lever was then slightly bent inward so it would not move unless by hand which fixed problem.
Anyway many times the e-unit needs to be looked at carefully .