Section 17. The supreme judicial or superior court may restrain the erection, occupation or use of a building in violation of section thirteen or of any regulation made thereunder.