There could be several reasons. Firstly, it could be a sign of a very unbalanced power dynamic in the friendship. The friend who spanks might feel superior in some way. Secondly, it could be part of a fictional world where the rules of normal behavior are distorted. Maybe the story is set in a place where there are strange social norms. Thirdly, it could be due to a major conflict or betrayal in the story. The spanking could be an extreme reaction to a perceived great wrong, but still, it's an inappropriate way to handle things in a friendship.
One possible reason could be a misunderstanding. Maybe the friend thought the girl had done something wrong that affected them directly, but instead of talking it out, they resorted to spanking out of anger or impulse. Another reason could be in a story set in a different cultural or historical context where physical discipline was more common among peers, although this is not common in modern friendships.