As @Milo said in his comment above, you need to use concatenation as this is a loop your in. So you need to add a value each iteration not replace it. Your $output=""
needs to become $output .= ''
. Notice the point/dot before declaring the value, in PHP this is used for concatenation.
//the loop
while($gallery_query->have_posts() ) : $gallery_query->the_post();
$output .= '<article class="masonry-entry" id="post-' . get_the_ID() .'" ' . get_post_class() .' >
<div class="masonry-thumbnail border">
<a href="' . get_post_permalink() . '" title="' . get_the_title() . '" class="inner-shadow">' . get_the_post_thumbnail(get_the_ID(), 'masonry-thumb') .'</a>
</div><!--.masonry-thumbnail-->
<div class="masonry-details">
<h5><a href="' . get_post_permalink() . '" title="' . get_the_title() . '"><span class="masonry-post-title"> ' . get_the_title() .'</span></a></h5>
<div class="masonry-post-excerpt">
' . getPostLikeLink(get_the_ID()) .' <p class="post-comment"><a href="' .get_post_permalink() . '"><i class="fa fa-comments qcomment" title="Comments"></i></a> ' . comments_number( ' ', '<sup>1</sup>', '<sup>%</sup>' ) . '</p>' . getBookmarkLink(get_the_ID()) . '
</div><!--.masonry-post-excerpt-->
</div><!--/.masonry-entry-details -->
</article><!--/.masonry-entry-->';
endwhile;