You can file a religious exemption at any time, but an employer may argue your religious belief isn’t sincerely held and that you’re only filing a religious exemption because your medical exemption was denied.
To alleviate this issue, tell your employer before filing an exemption that you have grounds for both, and ask (preferably in writing) whether you should file both exemptions — that way if you file one exemption and it is denied, it is documented you had grounds for both and you were acting on your employer’s recommendation. The other option is to file both exemptions from the outset so that if one is denied, you have the other to fall back on.