The documentation is very scarse, so I have tested it.
All tests I have done with commit & rollback on session variables (SET SESSION) have shown a clean transactional behavior, with the value reverted on ROLLBACK, whether intentional or automatic, or the new value set on COMMIT. See attached scripts for instance.
Your test shows so SET SESSION has not transactional behaviour - the transactions fails, but the value is not reverted to NULL.
It is good example of antipattern for this routine type :)