Create Shortcode for php code in functions.php

If your code works fine then do this in function.php

    <?php
    add_shortcode( 'custom_name', 'footag_func' );
    function footag_func( $atts ) {
    $html="";
    $posts = get_field('related_posts', false, false);
    $loop = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 3, 'post__in' => $posts, 'post_status' => 'publish', 'orderby' => 'post__in', 'order' => 'ASC' ));

    if($loop->have_posts()) { 
       $html .= '<div class="rel-posts">';

        while ($loop->have_posts()) : $loop->the_post(); 

           $html .= '<div class="related-post">';
            $html .='<a href="'.the_permalink().'">'.the_post_thumbnail('td_218x150').'</a>';
              $html .=  '<h3><a href="'.the_permalink().'">'.the_title().'</a></h3>';
           $html .=  '</div>';

        endwhile; 

   $html .= '</div>';
   } wp_reset_query(); 
    }
    return $html;
    ?> 

your shortcode
[custom_name]