So the goal is to find a way to react, with the following requirements
- to never be put in the same situation again
- to not upset the student
- to not lie
- to not make the situation worse
Let's take them one by one and then combine the solutions to find the optimal one.
- to never be put in the same situation again
I am afraid that you cannot control what people will say when they start talking with you. You can influence that by opening every discussion with something along the lines I don't speak about religious matters. In this way you will also get notoriety and perhaps some people will stop doing it. Still, it's not 100% effective. It might even have a boomerang effect, i.e. religious people to consider you're a lost soul needing guidance. Conclusion: No solution.
- to not upset the student
What did exactly upset the student? From what you said, it's the fact that you told the student that you do not have the same religion. So, to NOT upset the student, just reverse the previous phrase, i.e. do not tell the student that you do not have the same religion. We can go with the analyses further and think what would happen if you would not say that, but instead reply with something along the lines I do not want to speak about religion. I think the likely outcome of that would be that the student would still get upset, but that's just my assumption, you may try it out and come back to this answer. Alternatively you can lie and tell the student that you do have the same religion. I bet that would not upset the student. Conclusion: lie to the student and tell them that you have the same religion.
- to not lie
If you don't want to lie to the student, you obviously have to be honest. The way you proceeded is the most honest way. Conclusion: Be honest and tell the student that you do not have the same religion.
- to not make the situation worse
I don't know how you define worse, so I can't provide advice on that. Conclusion: No solution.
Let's put draw all conclusions and see how we can put them together:
- Conclusion: No solution
- Conclusion: Lie to the student and tell them that you have the same religion
- Conclusion: Be honest and tell the student that you do not have the same religion
- Conclusion: No solution
Solution 1, and 4 are incompatible with any other solution, so you either accept that there is no solution, or you change requirements 1 and 4. To go further, I'll assume you give up on these requirements, as I can't possibly know how you might want to change them.
Now we only have solutions 2 and 3. They are obviously incompatible. 2. says you should lie, 3 says that you should be honest, which are antonyms. You'll have to give up on one of the requirements 2 or 3.
In conclusion: You either pick 1 and 4 as a solution, or 2, or 3. One last alternative is to change the requirements all together, but that would just mean that you accepted 1 and 4, and you'd try to solve a different problem, wouldn't it?
Note 1: By this point I expect that some people will say that this answer is not helpful, as it doesn't give the OP a solution that matches all their requirements. To which I reply that you can't draw 7 red lines, 2 with red ink, 3 with green ink, and the rest with invisible ink, all perpendicular to each other.
Note 2: Some critics will say that my answer (lying and honesty are exclusive) is trivial. To which I reply that the question would not have existed if the solution would have been that trivial.