Change username to nickname in comment section

Yes, of course it won’t show any name for guest comments because they are not registered users of your website so they don’t have any nickname associated.

What you can do in this situation, is add a check before printing the nickname, if comment was made by a user or a guest. And act accordingly.

So this is the code you want to use instead.

if ( $comment->user_id != '0' ) {
    echo '<span class="some-class">' . get_user_meta( $comment->user_id, 'nickname', true ) . '</span>';
} else {
    echo '<span class="other-class">' . get_comment_author_link() . '</span>';
}

This checks if commenter user_id is 0 (for guests) then it will show guest name with link url (default) and if it is a user then it will print user’s nickname.