Prejudice was a critical component of keeping the institution of slavery acceptable in the eyes of non-enslaved people, particularly white people, but it was not, in and of itself, the creator of slavery. One could trace the origin of slavery back to the origin of civilization and the advent of agriculture and centralized hierarchy. Since the creation of hierarchy within civilization, slavery has existed in many forms across the world (which, perhaps, could signal the fundamental injustice of civilization).
In colonial America, slavery took on a particularly brutal and detrimental form—inherited chattel slavery. The early rulers of colonial America sought to become wealthy through gaining immense profit from selling crops produced through the work of unpaid laborers. The system of slavery initially began as temporary enslavement of indentured Europeans and African people. However, as production of crops grew, the colonies expanded through genocide and displacement of indigenous peoples, and as indentured Europeans and temporarily enslaved African people formed relationships and banded together, the ruling class decided to prevent a possible uprising of African and European people against the ruling class by creating a system of chattel slavery based on race and generational enslavement.
Through the creation of this system, the governments of the colonies began creating laws to uphold this system of permanent enslavement of African people via social, political, and economic means. The initial wave of these laws prohibited interracial marriages and relationships, severely punished interracial resistance against slave owners, allowed for specific brutality against enslaved African people, and punished interracial escape from indentured servitude/slavery by way of adding on additional years of servitude of Europeans and creating lifelong sentences of slavery for formerly temporarily enslaved Africans.
This punishment of lifelong slavery transitioned into a general practice. As this practice of lifelong enslavement grew, the colonies created laws that would cement this slavery by declaring that the child of an enslaved black woman would always be a slave. In order for this system to work, the state relied upon fear and subservience by enslaved people and acceptance of slavery by non-enslaved people and hatred of enslaved African people by non-enslaved people.
This hatred was brought about by creating incentives for working-class/indentured Europeans to treat enslaved Africans as inferior, creating myths and pseudo-science and religious justification of prejudice (the concept of "white" as a race was created by the colonial government to enforce their myths of white superiority), and enforcing prejudice through severely punishing inter-racial solidarity.