One should first stay calm. If it's a situation where it's a proper form of discipline, like in a family or school with clear rules, you can support the authority figure later by talking to your friend about why they got spanked. For example, if your friend was spanked for lying, you can tell them that honesty is important.
It depends on the context. If it seems unjust, you might need to step in carefully. Maybe talk to the person who did the spanking privately and express your concerns. Say, if your friend was spanked for something they didn't do, you can't just let it pass. You could say something like, 'I think there's been a misunderstanding. I was there and my friend didn't do what you think they did.' However, if it's a fair punishment, you can offer comfort to your friend afterwards by saying things like 'I know it hurts now, but you'll learn from this and be better.'