Codependency is often rooted in childhood and is caused by a child's emotional needs not being met by their parent. This could be the result of neglect, abuse, or a parent being mentally ill or addicted to drugs or alcohol.
Their childhood is chaotic, unstable, unsupported, or scary, but the child is told by their caregivers that they are to blame or that there isn't a problem in the first place. When the caretaker can't provide what the child needs, the child may instead take on the role of the caretaker, or learn that those who claim to love you cannot be trusted. Codependents see that their value only comes from pleasing other people, and they feel guilt for a lot of issues that aren't their fault.