Praise be to Allah.
The basic principle is that the mosque should be open and not locked, so that Muslims can pray in the mosque at any time. Dogs used to come and go in the mosque at the time of the Prophet (peace and blessings of Allaah be upon him), as it says in Saheeh al-Bukhaari. But if that leads to bad consequences such as evil things taking place inside the mosque, then it should be locked as a precaution, and because warding off bad things comes before attaining good things. The same applies is there is some danger to the mosque’s property such as furniture, machines, etc.