When analyzing such situations there are many factors to consider such as the safety of the people in an environment, in this case the school and the effect that searches of lockers has on the students and in this case it sets an example and is considered a way to discipline students.
Firstly, authorities do this for the safety of everyone in the environment. Individuals can bring harmful things such as drugs, knives and other weapons that can not only hurt themselves, but also put others in danger. And if searches were not conducted in situations where they should be, this could have further consequences, for example, the school would not be a safe place and many students would be putting themselves at risk of being physically and mentally abused.
Additionally, this is considered a way to discipline students. If the students know that school authorities have the right to do lawful searches, they know not to bring harmful possessions to school that can put their peers and themselves at jeopardy. The consequences of bringing such possessions could result in the involvement of Police and the individual(s) may be suspended or expelled from school.
In conclusion, authoritative people in a school environment, such as principal or teachers, have the right to conducts rightful and lawful searches where they feel that an individual is putting themselves and other students at risk.