I think that I understand what is going on here.
When you enable SSL, the server recycles itself. When, and if, the calls returns from enabling SSL; I followup by making another call. Subsequent calls will continue to fail until the server is functional again. I simply put this in a loop and try a certain number of times before giving up.
There are 2 obtuse problems here.
The first problem is that I believe there is a bug in ArcGIS Sever where it recycles before it returns a response from the call which enables SSL. In my case I have a single machine (i.e. localhost). You can easily see this by using the ArcGIS Server Administrator Directory and performing an update on security to enable HTTP and HTTPS. Try turning it on and off (HTTP only) several times. What you will see is that sometimes the browser hangs when enabling HTTPS.
The underlying code for this is in the SSLManager class. See enableSSLLocal and restartServersLocal in package com.esri.arcgis.discovery.admin which is in arcgis-admin.jar.
When I do this in code then my code hangs waiting for a response. The only workaround I see is to try to add timeout logic in my call to enable security.
The other problem, which is not an ArcGIS Server bug, is that the token I generated previously becomes invalid because the client ID changes when I subsequently use SSL. So, what I do is to generate a new token after enabling SSL.