Currently when changing the brush size, strength and many more tool specific settings it is added to the undo history. I think there is a bigger design discussion behind this if this should even be allowed but the bug that is tied to this is that these steps, when undone are not actually undone.
They are just extra undo steps that do nothing. And since when sculpting, painting or drawing it is very common to very often change the size & strength of the current brush, the undo history gets flooded with undo steps that don't undo anything.
To add my take on how this should be fixed: Tool settings should never be included in the default undo history, just like interface changes have no undo steps.
My suggestion would be to perhaps add a second undo history for settings and interface changes, but only if these should still be undo-able.