I attended a mosque as part of a classroom assignment when I was a Bible College student. I had to obtain approval from the professor, as the assignment was for students to attend a service at two different denominations than the one the student normally attended or identified with. Being a much older student than my classmates, and having already visited many different denominations in the course of my life, I proposed an alternative to the professor -> that I be allowed to attend a service at a mosque and a service at a synagogue. He initially rejected my proposal, but soon changed his mind after I persisted.
Did I pray in the mosque? Yes. Were the Muslims aware of it? No.
I was praying to the God of the Jews, not to Allah.
(Did I pray in the synagogue? Yes. Were the Jews aware of it? Yes and no.)
The imam knew I‘m not a Muslim. I went with my Muslim co-worker / friend. He knows I‘m not a Muslim. I suspect most of the Muslims knew I’m not a Muslim. I stuck out like a sore thumb, and they had arranged beforehand a special accommodation for me which served to emphasize the ”them vs. me” dynamic. (A few “Christian” members here persist in falsely accusing me of being a Muslim.)
What would the Muslims have thought if they knew I was praying during the service? What would they have said? What would they have done? I don’t know, but I suspect it might have caused an incident if they had known.
P.S.
I wasn’t there to teach them anything. I wasn’t there to evangelize them. I was there to learn about them, from them.