How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?

It seems that you are using Ajax Load More as a lazy loading method.
Your div is displaying only with the elements loaded with the “classic” WP query because the load more shortcode has nothing to do with the code you wrote: is other code, excuted when already your code was parsed, run, an done.

Skimming through its documentation I couldn’t find any way to insert yourself in the plugin’s own loop without tinkering directly with it’s source file, that is a bad idea.

My suggestion would be to, if you absolutely want to use that plugin to do lazy loading, leverage its complete callback function and insert, after the loading is done, your div dynamically counting every 5th post. You will need to setup ajax on frontend first.

Then you bind your special div to an ajax action:

function my_ajax_action(){
   echo "<div> Hello! </div>";
}
add_action( 'wp_ajax_nopriv_my_ajax_action', 'my_ajax_action' );

and call it from the frontend with some javascript, to place in the footer of the page you need this functionality.

$(function() {

jQuery.fn.insertAt = function(index, element) { //custom function, see below code
  var lastIndex = this.children().size();
  if (index < 0) {
    index = Math.max(0, lastIndex + 1 + index);
  }
  this.append(element);
  if (index < lastIndex) {
    this.children().eq(index).before(this.children().last());
  }
  return this;
}

  $.fn.almComplete = function(alm){ //this is the ajax load more's callback, view link in answer

    jQuery.ajax(//let's call our custom ajax action
    {
        type: "post",
        dataType: "json",
        url: my_ajax_object.ajax_url, //see link in answer about ajax setup
        data: { action:"my_ajax_action" }, //the custom action
        success: function(my_div){ //what to do when the div is returned from ajax
            jQuery('.loaded_posts').insertAt(4, my_div);
            jQuery('.loaded_posts').insertAt(9, my_div);
            //fixed values because you know how many posts you call
        }
    });
  }
})(jQuery)


I used the insertAt function from this answer.
Other resources were the WordPress page on AJAX