This is equivalent to the use of to in die, but not all. Only zu in German can correspond to To in English.
So this sentence can also be said to be Dan Gehen Wirzur (Zuder) mensa, which is true, but Germans generally don't say this, but use die Mensa to say that it is a matter of language habits, but it is also true ~
There is a grammatical phenomenon here, that is, in+A (the fourth case) stands for such an action, because Mensa is a feminine noun, that is, die Mensa.
Mensa's fourth box happens to be Mensa, so it is in Mensa.
For another example, if you change to a classroom, that is, der H? Rsaal, because of H. Rsaal is a masculine noun, so its fourth case is den H? Yes, you can say we are here? rsaal
As for being, it refers to the direction and what it refers to. Because Mensa, H. Rsaal and the like are all places that can be "inside", in is used here.
For another example, if we mean going to the market, that is, der Markt, we should say Dan Gehen Wirauf Denmarkt here.
Auf is used here because it refers to something. Markt is open-air, so in is not used here.
Is that clear?