Form API #ajax
effectively disables behaviors on elements. I can't see this documented, but that's how it works, consistently. So the solution was to change the line:
$('#edit-categories-update', context).on('click', function(){
and make it
$('#edit-categories-update').ajaxSuccess(function() {
That way code was not executed on click, but after processing of AJAX triggered by the button succeeded. It's not useful if you want to perform JavaScript before AJAX call, but if you need it to happen after, or if you don't care, it is a sufficient solution. If you need things to happen before AJAX call, use this instead:
$('#edit-categories-update').ajaxStart(function() {