Short answer:
You have a logical error in your code, this condition is wrong:
if($wpdbupdate === 0)
Replace it with:
if($wpdbupdate >= 0)
and it will work as expected.
Long explanation:
$wpdb->update method returns the number of rows updated, which is 1 in your case, so your code continues to the next block and status 400 is assigned.
See WP documentation on $wpdb->update: https://developer.wordpress.org/reference/classes/wpdb/update/
Return #
(int|false) The number of rows updated, or false on error.
Your code only returns status 200 when nothing is updated and $wpdb->update returns zero, and the strange behaviour goes by this scenario:
- table row updated, the update returns 1, which triggers status 400
- nothing is updated on second attempt, the update returns 0, which triggers status 200
To fix this, change your if condition to
if($wpdbupdate >= 0)
to return status 200 when a row is updated or ignored (because the update contains value equal to the existing one), or
if($wpdbupdate > 0)
to return status 200 only if a value is changed