Background Rule-violating behaviour in the form of substance misuse has been studied primarily within the context of prison settings, but not in forensic psychiatric settings. Aims Our aim was to explore factors that are associated with substance misuse during hospitalisation in patients among those patients in a Swiss forensic psychiatric inpatient unit who were suffering from a disorder along the schizophrenia spectrum. Methods From a database of demographic, clinical and offending data on all residents at any time between 1982 and 2016 in the forensic psychiatric hospital in Zurich, 364 cases fulfilled diagnostic criteria for schizophrenia or a schizophrenia-like illness and formed our sample. Any confirmed use of alcohol or illicit substances during admission (yes/no) was the dependent variable. Its relationship to all 507 other variables was explored by machine learning. To counteract overfitting, data were divided into training and validation set. The best model from the training set was tested on the validation set. Results Substance use as a secure hospital inpatient was unusual (15, 14%). Prior substance use disorder accounted for so much of the variance (AUC 0.92) that it was noted but excluded from further models. In the resulting model of best fit, variables related to rule breaking, younger age overall and at onset of schizophrenia and nature of offending behaviour, substance misuse as a minor and having records of complications in prior psychiatric treatment were associated with substance misuse during hospitalisation, as was length of inpatient treatment. In the initial model the AUC was 0.92. Even after removal of substance use disorder from the final model, performance indicators were meaningful with a balanced accuracy of 67.95, an AUC of 0.735, a sensitivity of 81.48% and a specificity of 57.58%. Conclusions Substance misuse in secure forensic psychiatric hospitals is unusual but worthy of clinical and research consideration because of its association with other rule violations and longer hospitalisation. More knowledge is needed about effective interventions and rehabilitation for this group.