Short Answer: Basically, tahajjud is voluntary, so it’s not required of you. Moreover, if your doctor has advised you against it, know that harming your body for the sake of worship robs you of the benefits of that extra worship. We must care for our body, and this is also an act of worship. Maybe try one of these simple suggestions, however, that may not negatively impact your health.
Salaam and thank you for your question.
There is no simple answer other than –tahajjud is voluntary. Having said that let’s see what we can find out.
Allah Desires Ease for Us
Allah tells us in the Quran,
God desires ease for you, and desires not hardship. [Qur’an 2:185]
Allah burdens not a person beyond his scope. [Qur’an 2:286]
And Prophet Muhammad said,
Do those deeds which you can do easily, as Allah will not get tired [of giving rewards] till you get bored and tired [of performing good deeds! … and the most beloved deed to Allah is the one which is done regularly even if it is little [Bukhari]
If I command you to do a thing then, do as much of it as you can. [Bukhari and Muslim]
Muslims are obligated to look after their health.
If the doctors have prescribed medicine and/or a routine for you to follow, in the best interests of your health you should follow it.
However, I understand you enjoy tahajjud and would like to offer the prayer. Practically there are possibilities.
For example, you could pray tahajjud:
1) Before sleeping (qiyyam)
2) After sleeping
I’m sure a quiet place can be found where you could offer the prayer with due concentration and humility in tranquillity.
In the summer, where the nights are quite short, typically Isha’ is about 11pm and Fajr may be as early as 3am, sleeping would be a problem for you.
Would it be possible for you to sleep between Maghrib and Isha’ and sleep again after Fajr?
Be sure to consult with your doctor, of course, before attempting any of these suggestions.
Remember: Caring For Your Body Is Worship, Too
Please keep in mind what you are trying to do is voluntary and there is no punishment if the prayer is not performed.
Although missing out on the benefits of tahajjud is unfortunate, if there is an adverse affect on your health if you tried, you would be deprived of the benefit anyway.
I add this as I believe headaches may start or get worse when you lower your head as in ruku’ and sujood.
Scholars have deduced that it is allowed to pray while standing, sitting, or [lying] on our sides under some circumstances when our health dictates it.
This is especially true in the case of nafl (extra) prayers!
Keep in mind that if you can bow and prostrate without getting a headache then you MUST.
But, in the event you cannot, then for ruku’ you could sit and incline your head a little, then stand, then sit for sujood and incline your head just a little more than you did in ruku’.
I understand your desire to pray tahajjud and have tried to give you practical suggestions.
However, Allah knows your intentions and He will reward you accordingly.
There is no benefit in harming your health by doing optional worship.
May Allah bless you, make it easy for you and grant you health and healing, Amin.