The reason it is a draft, and what you need to do to get what you wanted is spelt out in the source code for wp_untrash_post
and in the documentation for wp_untrash_post_status
:
$new_status = ( 'attachment' === $post->post_type ) ? 'inherit' : 'draft';
/**
* Filters the status that a post gets assigned when it is restored from the trash (untrashed).
*
* By default posts that are restored will be assigned a status of 'draft'. Return the value of `$previous_status`
* in order to assign the status that the post had before it was trashed. The `wp_untrash_post_set_previous_status()`
* function is available for this.
*
* Prior to WordPress 5.6.0, restored posts were always assigned their original status.
*
* @since 5.6.0
*
* @param string $new_status The new status of the post being restored.
* @param int $post_id The ID of the post being restored.
* @param string $previous_status The status of the post at the point where it was trashed.
*/
$post_status = apply_filters( 'wp_untrash_post_status', $new_status, $post_id, $previous_status );
https://developer.wordpress.org/reference/hooks/wp_untrash_post_status/
By default posts that are restored will be assigned a status of ‘draft’. Return the value of $previous_status in order to assign the status that the post had before it was trashed. The wp_untrash_post_set_previous_status() function is available for this.
Prior to WordPress 5.6.0, restored posts were always assigned their original status.
So use that filter and add wp_untrash_post_set_previous_status
to it which was built specifically for this problem:
https://developer.wordpress.org/reference/functions/wp_untrash_post_set_previous_status/
Notice its source code is super simple