If the time is sufficient to perform ghusl but the ghusl would cause harm to the body, then it is obligatory to switch to the tayammum. If the time is not sufficient to perform the ghusl and the ghusl would not harm the body, tayammum is not obligatory. One can perform the ghusl even if this leads to offering the prayer outside designated time of the prayer.