There are several potential reasons. In some cases, it might be a cultural thing that has been misinterpreted or carried too far. For example, if there is a cultural background where light physical contact is used as a form of friendly teasing, but in the high school or college context, it becomes something more extreme. Also, it could be a result of peer pressure. If a group of boys is doing it as a 'cool' or 'edgy' thing, others might follow suit even if they don't fully understand or support it. And in some unfortunate situations, it could be related to underlying aggression or a lack of proper social skills training.
One possible reason could be a misconstrued sense of humor. Some boys might think it's funny in a juvenile way without realizing the inappropriateness. Another reason could be related to hazing in some fraternities or groups in college, which is an unacceptable practice. In high school, it could be a form of bullying, where one boy tries to assert dominance over another through this rather odd behavior.
Possible reasons can vary widely. It could be a form of misguided bonding. Some guys might think that this kind of physical interaction is a way to show closeness, similar to roughhousing but taken to an inappropriate level. In high school, it could also stem from immaturity and not fully understanding boundaries. In college, there may be instances where it's part of a dysfunctional group dynamic, like in some exclusive clubs where there are strange initiation rites. Additionally, it could be related to personal insecurities, where one male tries to feel more powerful or in control by spanking another, which is clearly an unacceptable way to deal with such issues in an educational environment.