Hey there rabia1rehman,
Thank you for using the Apple Support Communities! It's my understanding that you are experiencing intermittent issues with the flashlight option on your iPhone. I can help.
When it comes to using the flashlight on your iPhone, you can also use Siri to activate it. Does it fail to work when you use Siri to activate it as well? If the option is not greyed out but the flash still does not work, have you tried adjusting the brightness as shown in this support article too? If not, give that a go for me.
How to use the flashlight on your iPhone, iPad Pro, or iPod touch
You did a great job researching a possible cause regarding the temperature of your device. When you open the camera and try to turn on flash to take a picture, do you get any type of alert or error? If you've ruled out temperature as a possibility, I'd like to have you Contact Apple Support so we can help check for hardware issues. You can also visit with your local Apple Store or Apple Authorized Service Provider: Apple - Find Locations - Location Selector
Thanks again for using the Apple Support Communities.
Take care!