The capacitor should just be across the lower resistor of the divider, then you won't be loading the
24V sensor output overly - it may not be designed for a capacitive load. 10nF may be plenty, experiment?
Basically the place to reduce interference is directly at the source, and right at the input to the Arduino.
You may have poor choice of cable layout with sensor and motor wiring alongside? Avoid this, motor
power wiring is usually quite noisy and it should be kept away from your sensors and their wiring for
a quiet life (!)