Prayer and fasting of a prisoner who does not know anything about time
Question

                How can a person who is jailed in an underground room pray, while he is chained, heedless about prayer times, and does not know that Ramadan started?.
Praise be to Allah.
    Firstly:

    We ask Allaah to grant all Muslim prisoners a rapid release, 
    and to grant them patience and consolation by His bounty, and to fill their 
    hearts with peace and certainty of faith, and to make easy for the Muslims a 
    way of guidance whereby His close friends will be honoured and His enemies 
    will be humiliated. 

    Secondly: 

    The scholars have determined that prayer and fasting are not 
    waived for prisoners and detainees, and that what they must do is to try 
    their best to work out the right times. If the prisoner thinks it most 
    likely that the time for prayer has come, then he should pray, and if he 
    thinks it most likely that Ramadaan has come, then he should fast. He can 
    work out the times by noting the times when he is fed, or by asking the 
    guards and so on. 

    If he tries to work out the right time for praying and 
    fasting, then his worship will be valid and acceptable, whether he finds out 
    later on that he did it at the right time, or after it, or he does not find 
    out anything, because Allaah says (interpretation of the meaning): 

    “Allaah burdens not a person beyond his scope”

    [al-Baqarah 2:286]

    “Allaah puts no burden on any person beyond what He has 
    given him”

    [al-Talaaq 65:7]

    But if he finds out that he fasted on the days of Eid, he 
    should make them up, because fasting on the days of Eid is not valid. 

    But if he finds out later on that that he prayed or fasted 
    before the proper time, then he has to repeat the fast or prayer. 

    It says in al-Mawsoo’ah al-Fiqhiyyah (28/84-85): 

    The majority of fuqaha’ are of the view that if the months 
    all seem to be the same to a person, the fast of Ramadaan is not waived in 
    his case, rather it is still obligatory because he remains accountable and 
    the ruling still applies to him.  

    If he tries to work it out and he fasts, then one of the 
    following five scenarios must apply to him: 

    1 – The problem continues and he cannot find out, so he does 
    not know whether he managed to fast at the time of Ramadaan or before it or 
    after it. In this case his fast is valid and he does not have to repeat it, 
    because he did his best, and he is not required to do any more than that. 

    2 – The fast of the prisoner coincided with Ramadaan, so that 
    is acceptable. 

    3 – If his fast happened to be after Ramadaan, that is also 
    acceptable according to the majority of fuqaha’. 

    4 – There are two possibilities with the fourth scenario: 

    (i)If he started fasting before 
    Ramadaan, and he finds out about that before Ramadaan comes, then he must 
    fast when Ramadaan comes, and there is no difference of opinion among the 
    scholars concerning that.

    (ii)If he started fasting before 
    Ramadaan and he did not find out about that until after it had finished. 
    There are two opinions as to whether this is acceptable:

    (a)It is not acceptable for 
    Ramadaan, rather he has to make it up. This is the view of the Maalikis and 
    Hanbalis.

    (b)It is acceptable as Ramadaan, 
    just as if the pilgrims are uncertain of the day of ‘Arafah and they observe 
    the standing before the day. This is the view of some of the Shaafa’is.

    5 – If the fast of the prisoner coincides with one part of 
    Ramadaan and not the other; that which coincides with Ramadaan or comes 
    after it is acceptable, and that which comes before it is not acceptable. 
    End quote. 

    See: al-Majmoo’ (3/72-73) and al-Mughni (3/96) 

    And Allaah knows best.