How to convert custom post type based list to a dropdown list?

the_title() and the_permalink() are functions that automatically echoed. Use in this case get_the_title() and get_permalink().

the code should look something like this:

while ( $query->have_posts($post->ID) ) : $query->the_post();
    echo '<li><a href="'. get_permalink(). '">' .get_the_title() .'</a></li>';  
endwhile;

Here is another way using the_title and the_permalink:

while ( $query->have_posts($post->ID) ) : $query->the_post(); ?>
   <a href="https://wordpress.stackexchange.com/questions/191514/<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php endwhile;