How to allow editors to only edit certain categories?

You can hook into the pre_post_update action hook, and check both post’s category and editor. Here’s a quick example:

// Hook to save_post to do some checks
add_action( 'pre_post_update','wpse315124_save_post_check' );
function wpse315124_save_post_check( $post_id, $post_data ){
  // Check user's role and post's category
  if( 
        has_category ( 'some-category', $post_id ) &&
        current_user_can( 'editor' )
    ) {
      // Stop the script
      wp_die( __( 'You can not edit this post.' ) );
  }
}

You can also run additional tests, such as get_current_user_id() and check the id to match specific users/categories.