The primary motivation behind the south enacting the black codes was to prevent African Americans from achieving political and economic autonomy, thereby keeping white supremacy in place.
Black codes were a series of discriminatory state laws collectively passed by southern states.
The purpose of enacting such laws was to economically disable freed slaves, forcing them to continue to work on plantations and to remain subject to racial hierarchy within the southern states.