The welfare of animals under human care is often assessed by observing behaviours indicative of stress or discomfort, such as stereotypical behaviour (SB), which often shows as repetitive, invariant pacing. Traditional behaviour monitoring methods, however, are labour-intensive and subject to observer bias. Our study presents an innovative automated approach utilising computer vision and machine learning to non-invasively detect and analyse SB in managed populations, exemplified by a longitudinal study of two polar bears. We designed an animal tracking framework to localise and identify individual animals in the enclosure. After determining their position on the enclosure map via homographic transformation, we refined the resulting trajectories using a particle filter. Finally, we classified the trajectory patterns as SB or normal behaviour using a lightweight random forest approach with an accuracy of 94.9 %. The system not only allows for continuous, objective monitoring of animal behaviours but also provides insights into seasonal variations in SB, illustrating its potential for improving animal welfare in zoological settings. Ultimately, we analysed 607 days for the occurrence of SB, allowing us to discuss seasonal patterns of SB in both the male and female polar bear monitored. This work advances the field of animal welfare research by introducing a scalable, efficient method for the long-term, automated detection and monitoring of stereotypical behaviour, paving the way for its application across various settings and species that can be continuously monitored with cameras. We made the code publicly available at https://github.com/team-vera/stereotypy-detector.