This is a semi-ridiculous question from a law-ignorant but curious person. My apartment prohibits tenants from having firearms on the property, by the lease. in the United States, the "right to bear arms" is a constitutional right. (I understand there's disagreement about what that means, that things are more complicated than just that phrase, and etc.) So, theoretically, can an apartment 'infringe' on other constitutional rights as well, such as freedom of speech, as long as it's in the lease, and the tenant signs?
Firstly, your "apartment" doesn't prohibit anything; Your tenancy contract does. A terminology nitpick, but one that can shed some light on what is actually happening.
TLDR: Your right to bear arms isn't being infringed, its being traded away. An unreasonable trade may be invalidated by the courts. Firearms restrictions are far less likely to be voided than speech content limitations.
Yes, you have the right to bear arms(whatever exact meaning of that is). You also have the right to voluntarily agree to a binding agreement limiting that right, in exchange for a consideration.
Compare a Non-Disclosure Agreement (NDA). You have the right to freedom in your speech: you also have the right to agree to binding limits on your freedom of speech, in return for consideration (such as money or access to information).
Every contract is structured in the same general way: Party A agrees to do or avoid doing certain things, in exchange for Party B agreeing to do or avoid doing certain things.
So, in essence, what the apartment contract says is, that you agree to do or not do some things (including paying rent), in return for your landlord temporarily granting you some rights(such as the right to reside(generally exclusive), the right to control the space, etc. ), and imposing some obligations on themselves (which vary from place to place). In your case, one of the things that you are trading is a limitation on your right to bear arms(note that you can still bear arms, just not on the property in question).
Now one thing to note is that courts have the power to enforce contracts; they also have the power to void contracts, in part or in full, if they are illegal or "unconscionable". In general, restricting (the content of) speech is not reasonable (e.g. having a general noise level restriction is reasonable), so is more likely to be struck down than one restricting firearms on the rented property.