If the images are static (as in, no animation) there are several libraries out there that handle stuff like this. I don't know of any off the top of my head but they are often called "paper doll" or "human avatar" systems. If the characters are animated, it gets a bit more complicated then and no off-the-shelf library is going to meet that need. At that point it becomes more about trying to find a way to prevent having to animate all of the pieces of clothing, hair, etc. That is why in most 16-bit era RPGs, character's hair and shirt don't move when they walk so they just need the 3 directions of the hat and shirt art assets (you only need one left or right of course, since they can be reversed) and position them over the base avatar sprite.
The indelible lord of tl;dr