I tested your v1 on master, REL_18_STABLE and REL_17_STABLE, together with Andrey's v2 for #19621 [1], which touches the same function. Both apply cleanly on all three branches, build without warnings, and the main regression suite passes. On all three, JSON_VALUE(x, '$' RETURNING jsonb) over '1', 'null', '2' now returns 1, NULL, 2 (it was 1, NULL, NULL).
The fix looks right to me: that branch fills val_string but never cleared the resnull left by an earlier row.
A small thing: git apply warns about trailing whitespace on four lines of the new test in sqljson_queryfuncs.sql.