Strange issue with gallery when displays 3 columns

Couldn’t you make it shorter by doing the following?

function meks_gallery_atts($output, $pairs, $atts)
{
  $output = array();
  if (in_array($output['size'], array(1,2,3,4,5,6,7,8))) {
    $output['size'] = 'square_thumb_' . $output['size'];
  }else{
    $output['size'] = 'square_thumb_9';
  }
  return $output;
}

It sounds like $atts[‘columns’] is never 3. Have you tried strict-checking on strings, rather than loose-checking on integers?

is using this:
if ($atts['columns'] === '1') {
instead of this?
if ($atts['columns'] == 1) {

Aside from that… maybe try this to debug & see what that value of 3 really is?

function meks_gallery_atts($output, $pairs, $atts)
{ var_dump(array($output, $pairs, $atts)); exit;