Index: src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
===================================================================
--- src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php	(revision 39282)
+++ src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php	(working copy)
@@ -385,11 +385,17 @@
 			return new WP_Error( 'rest_comment_invalid_status', __( 'Sorry, you are not allowed to set status for comments.' ), array( 'status' => rest_authorization_required_code() ) );
 		}
 
-		if ( empty( $request['post'] ) && ! current_user_can( 'moderate_comments' ) ) {
+		 if ( empty( $request['post'] ) && ! current_user_can( 'moderate_comments' ) ) {
 			return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => rest_authorization_required_code() ) );
 		}
 
-		if ( ! empty( $request['post'] ) && $post = get_post( (int) $request['post'] ) ) {
+		if ( ! empty( $request['post'] ) ) {
+			$post = get_post( (int) $request['post'] );
+
+			if ( ! $post ) {
+				return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) );
+			}
+
 			if ( 'draft' === $post->post_status ) {
 				return new WP_Error( 'rest_comment_draft_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) );
 			}
