If you go to jail you can (and usually will) temporarily lose your social security benefits. However, after you are released, you can apply to have them restored.
If you receive a monthly check for a disability, the checks will continue while you are in jail. Jail time will not affect your ability to apply for benefits at a later date, either.
You won't lose your social security while you are in jail. However, you may well be forced to pay for your incarceration, and thus your social security won't get saved away for you.
You are not eligible for social security for any of the time that you are incarcerated in a jail. This also applies too halfway houses, boot camps or dentetion centers.