WP Rest Api / Ajax POST not working when not logged in

As stated in the documentation page you linked,

It is important to keep in mind that this authentication method relies on WordPress cookies. As a result this method is only applicable when the REST API is used inside of WordPress and the current user is logged in. In addition, the current user must have the appropriate capability to perform the action being performed.

Your JavaScript function is attempting to update a post – an interaction which affects the site’s database. Thus the REST API requires authentication in order to perform the operation. While REST authentication behaviors can be modified using the rest_authentication_errors filter, it’s highly inadvisable to disable authentication for the requests which require them by default, as doing so exposes your site to modification at virtually anyone’s whim.

You may wish to investigate alternate means of authentication, as alluded to in the documentation page you linked.