One function was straight up punishment for when the slaves did something bad. Another was that they felt that it would serve as a reminder to all other slaves not to try and do anything bad or they might end up like them. Another can be that they wanted to protect women because they believed that the African Americans wanted to be with their women while the opposite was actually true.