Adding a custom page template to a plugin generated page

You can set the page template by calling update_post_meta() with a key of ‘_wp_page_template’.

Or while inserting posts, you can pass page_template to wp_insert_post().

See: https://developer.wordpress.org/reference/functions/wp_insert_post/#more-information