This is useful for test cases where we want to test logic invalid blocks that contain witness transactions. If we don’t add the witness commitment as per BIP141, blocks will be rejected with the error Block mutated
.
This change was needed in https://github.com/ajtowns/bitcoin/pull/13 which is a soft fork proposal to disallow 64 byte transactions. We want to test that 64 byte transactions serialized without the witness are invalid. If we do not have this change, we cannot directly test the logic that rejects 64 byte transactions.
I decided to PR this upstream as many soft fork proposals may not see the light of day, but this functionality seems strictly additive to the test framework.