Set default number of columns in gallery

You can override many of the Gallery Settings using the media_view_settings filter:

/**
/* Gallery Default Settings
/* @param Array $settings
/* @return Array $settings
*/
function theme_gallery_defaults( $settings ) {
    $settings['galleryDefaults']['columns'] = 5;
    return $settings;
}
add_filter( 'media_view_settings', 'theme_gallery_defaults' );

To change more settings, the easiest way is to use Developer Tools to inspect the actual field. What you’re looking for is an attribute called data-setting. Grab that value and use it to override the defaults.

Of course it should be noted that this will not update galleries that already exist. You’ll have to run a filter on the_content to change it on the fly.

Credits: https://wordpress.stackexchange.com/a/169491/7355