All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger. We ask Allaah to exalt his mention as well as that of his family and all his companions.
If the owners of such premises do not allow people to use them except for those who reside in them, or that the custom suggests so, then it is not permissible to use them. However, if they give permission for anyone to use them, or that it is known that they give permission for everyone, or that this is the custom, then it is permissible to use them. This is of course if one is in dire need to use them, otherwise it would be permissible even if they do not usually allow people to use their toilets, as necessity has its own rulings.
Allaah Knows best.