To try and reproduce this, I visited the CiviCRM.org demo site at https://dmaster.demo.civicrm.org/, logged in, and explored the API Explorer there. You might prefer to use a demo site that matches your platform / version (& note that some folk have found the CiviCRM.org hosted demo sites can be hard to spot beneath the partner-hosted sites on that page).
I found a contact via the regular CiviCRM UI and edited their "Marital Status" and "Most Important Issue" constituent info on the contact edit screen, then used the API explorer to return the custom data which had been set.
I then used the same process to try and update the custom data, setting "Marital Status" to "M" (the API explorer presents available options in a list).
This showed a successful result and I confirmed that the update worked by viewing the contact record and seeing that "Other" had now changed to "Married". This indicates that the CiviCRM.org demo site works for this use case (suggesting that the issue you're experiencing might be configuration or permission-dependent, or related to some other site-specific implementation detail).
By observing the network tab while testing these API calls, I could observe the response from CiviCRM. In the event where an API call via JS doesn't return a result, I'd look here to see if there was an unexpected response (either invalid JSON, which could possibly leave CiviCRM's JS API hung, or an HTTP response code other than 200, which might have similar results).
I see your posted code is PHP not JS, so it may be you aren't using the JS API and can discount the HTTP layer as causing your issues. In that case your next step is probably to inspect the result of the attempted API call, and to investigate error logging (also valid when you are using CiviCRM's HTTP/JS interface).
In that case, inspecting details recorded to the CiviCRM debug log, and your hosting environment's PHP and webserver logs can reveal if there's any indication of an issue there. This question has a detailed writeup on where to find the debug log and other logs, as does the CiviCRM docs.
There's a related question on setting custom data via API which suggests that custom data is not consistently supported by various entity types when modified using the API. That's an old question and might not be up to date.
Hope this is some help!