Create a sitemap without a plugin – get parent pages only?

You have to slightly modify your query on your above code as:

 $postsForSitemap = get_posts( array(
        'numberposts' => -1,
        'orderby'     => 'rand',
        'post_type'   => array( 'page' ),
        'post_parent' => 0,
        'order'       => 'DESC'

    ) );

if you want all page without parent as you have used to get parent pages only.
It will generate a sitemap.xml file and update the links (URLs) with the most recent first (last modified) after you create/update the page.

Hope that helps!!