It depends on what you're doing with the motor.
If all the MOSFETs in the H-bridge are off, and the motor is turning, then it will act as a generator. The MOSFET body diodes will act as rectifiers, and rectified voltage from the motor will appear on the H-bridge supply rail.
Thus there is a possibility of over-voltage, but it depends on voltage and energy.
Voltage generated by the motor is proportional to rpm. At any rpm, the motor's voltage output will be a bit higher than the voltage that would be necessary to spin it without load at the same rpm. In fact it may be slightly higher, since the motor is unloaded when it acts as a generator.
So, if the motor will never be forced to turn faster than it would when unloaded and at full power, no overvoltage should occur. This would be the case for a drill, for example.
However, in other cases like an vehicle or a fan, the motor can be forced to turn faster, which means it will generate higher voltage than your power supply. Depending on how much, this may destroy your components.
The problem with your capacitor idea is that a capacitor of reasonable size can only store a small amount of energy, and the more energy it stores, the more voltage will rise. So it won't solve the problem. The role of the capacitor here is:
Provide decoupling, by lowering the impedance of the power supply at high frequency right on your board
Reduce noise, as high frequency harmonics from the PWM current will go through the cap rather than the battery wires
Absorb voltage spikes to prevent blowing the MOSFETs
And finally, slow down the voltage rise so the protection circuit has time to act when the motor acts as a generator.
As for the value, it is not critical. It should not be too large, otherwise you will have a huge current spike when connecting the battery, as the capacitor will immediately charge to full supply voltage. So if you use a Lithium battery with a BMS, and the cap is too large, the current spike may simply cause the BMS to think the output is shorted and disconnect. If that happens then you'll need a circuit to limit current while charging the supply caps, then connect directly to the battery.
It should not be too low, otherwise it is useless. The value depends on your battery, length of wires, PWM frequency, etc, so it's hard to say.
In any case:
If the motor can never be spun by an external force, then a capacitor will be enough to absorb voltage spikes.
If voltage can rise to dangerous levels because the motor can be spun by an external force, then you need something able to limit the voltage while absorbing all the energy generated by the motor, which can be a lot. The usual way is to detect overvoltage with a comparator, and when that occurs, turn on both low side MOSFETs. This shorts the motor, causing it to act as a brake, and the energy will be dissipated in the internal resistance of the motor windings.