Examine all the real impedances of your power components and compute the Q of the resonant system
DRV8402, RdsOn = 90 mΩ typ. x 2 in series. = 180 mΩ
Cap 3000 µF 25V ,ESR=20~250 mΩ, depends on size, quality, Voltage rating
Inductor 12mH ?? , ESR=40mΩ to ?Ω depending on rating
Motor Locked rotor Impedance = Rs +jX(f) =Zm(f)
Motor Equivalent Inductance during problem
A step load response to the motor depends on the "%load regulation" or impedance ratio of source/load impedance whenever a step voltage or current or step load is applied.
Thus it is intuitive that the lower the source impedance at the driving frequency, the less effect the load has on the source voltage or current and thus better mechanical stability, at low frequencies, but higher series electrical Q of the driving switcher rate.
This is an inherent challenge to regulate the rate of change of motor phase with position feedback and sensing motor current to prevent oscillations when the source impedance cannot be lowered. This is why VFD's are so popular since the driving force is modulated to match the motor pole frequency with current negative feedback giving a much lower output impedance.
But in my mind a battery for a variable DC motor in parallel with the 24Vdc using PWM , I think would work 100~1000x better than a 3mF cap because of the 50kF capacity of lead acid batteries and mΩ levels of ESR.
Motor position , velocity and acceleration (current) feedback will improve the stability by controlling each with a servo target profile, rather than open loop voltage step. i.e. Accelerate to new RPM, de-accelerate when RMP error is low and lock on to RPM will lower the driver impedance by huge amounts and improve system response time.
If you know a Step Input has infinite fourier spectrum, you can expect any resonances to be excited. But if you input a controlled Ramp, the Frequency spectrum is like a low pass filter and a 2nd order ramp even more. Thus system harmonics are unlikely to be stimulated much. Make sense?
But not having seen the whole design, this is just a guess.