When visiting a mosque, it matters if the imam is really a Muslim. Otherwise, why would one listen to his speeches? When celebrating an important islamic day, it matters if the people around you are Muslim. Otherwise, why would you celebrate with them?
However, not being a Muslim has consequences. In some countries, such as Indonesia, it is mandatory for adults to choose some religion which makes islam an obvious choice but it does not necessarily make someone a Muslim. People in such countries who are actually atheist need to pretend being religious in order to prevent negative legal consequences. In addition, in countries with a higher level of religious freedom, there is a similar problem. An imam who stops believing in god, can loose his job when he admits that. In some families, admitting not being religious anymore can have negative consequences too. People who are relegious may be shocked or angry. As a consequence of this all, there are atheist who say that they are Muslim.
So there is a problem. Like I explained, it is important to know who around you is Muslim. However, people who say that they are muslim may not be a truely believing Muslim.
How should Muslims deal with this discrepancy to know who around them is Muslim or not?