It can't but that's not due to the proposed solution for withers.
The cause is Records themselves. Record are immutable on purpose and you want to add a mutation constraint whish will not play nicely.
The proposed constraint will be triggered in this case :
var r = retrieveFromDb(); (value is A)
r = r.with(C) -> throw an exception
But this only work if B is generated by the wither. If I deconstruct the record manually and reconstruct with C manually, it'll work. So this offer no garantee that this transition will never occur.
I would even argue that this constraint can't be implemented at the level of the class, at least if the class is only a data carrier without external dependencies.