The capacitors are there to suppress the electrical noise caused by brushes. On a DC system the caps prevent the "noise" from propagating down the supply line (wires, wheels, track) which then acts as an antenna. Brush "noise" occurs at a broad range of frequency so any number of radio devices may pick it up. For example, without the capacitors your favorite FM channel may get staticy when your DC train passes certain areas of the layout.
With DCC and RP systems there is no antenna effect because the motor is driven by a PWM module in close proximity. There is no wide spectrum noise emission and thus no need for capacitors. On a PWM system the capacitors may have a small effect on the square wave being fed to the motor. They may round off the edges so to speak. Whether that is noticeable or not depends on myriad factors.
Personally, I would leave them in place for a DC layout. Remove them for a DCC or RP layout.