How to add custom class to last post In A loop wordpress

Put this below code in Function.php File and Save.

function last_post_class($classes){
    global $wp_query;
    if(($wp_query->current_post+1) == $wp_query->post_count) $classes[] = 'Your Class Name';
    return $classes;
}
add_filter('post_class', 'last_post_class');
 

  After this you display your class name in your last Post.