Actually, during the term of incarceration the individual holds NO rank. They are classified as "Prisoner" and lose ceertain privileges that those outside the military seem perplexed by, such as not having the right to salute. For instance, during morning and evening "Colors" formations (raising and lowering of the national ensign) they are requireed to remove their head covering and hold it over their heart. When a commissioned or warrant officer passes by they are required to offer an appropriate greeting but may not render a hand salute, nor may they remove their head covering. They are required to offer an appropriate greeting to all superior enlisted ranks (meaning anyone who does not have a large "P" on their back and right thigh.
Although the individual holds no rank while incarcerated, they may in fact have not been reduced in rank as part of the punishment inflicted imposed. Because they are not serving "good time" their eligibility to receive pay remains in suspense. Once they are released from incarceration they may again receive pay.
Back in the days when dinosaurs roamed the Earth and I spent the King's shilling "bad time" did not count towards the expiration of your enlistment contract. Sign for two, get locked up for five, and you spend a total of seven by the calendar but only two towards pay, rank, and benefits. I have no idea if they have gone soft in the intervening years. Officers agree to a certain period of service but have the option of resigning their commission before that term expires. Based on what inducements the government provided in return for signing up it may carry a heavy financial burden to resign your commission. (JAG officer had law school paid for by Uncle Sugar in return for six years service after graduation. He bailed after just over three. They presented him with the total bill for law school, with accrued interest. They wanted payment RFN, but he was able to arrange a payment schedule. He claimed to be surprised they wanted their money at all.)
stay safe.