Short answer
In most countries, yes. Most mosques welcome visitors and many hold open days. The exception is the Sacred Mosque in Mecca and the area around it, which only Muslims may enter.
The fuller answer
When visiting, dress modestly: covered shoulders and knees for men and women, and a headscarf for women, which many mosques provide. Take your shoes off before entering the prayer hall, keep your voice low and do not walk in front of people who are praying. Ask for the best time, since there is usually a quiet period outside of the prayers.
Visitors are not required to take part in the prayer, and you are free to ask the imam or a volunteer questions. Many mosques will be happy to answer them. The Prophet ﷺ allowed a delegation of Christians from Najran to pray in his mosque in Medina.
This answer follows the mainstream Sunni understanding and is general learning, not a fatwa. Where Muslims differ, the answer says so. Have a question of your own? Write to us.