The term gui (鬼) in guizi (鬼子) is an adjective that can be used to express hate and deprecation, an example being the local's expression of their hatred towards the Japanese during their occupation of China in World War II with the same gui (鬼).
The character gui (鬼) itself can have negative connotations, even without the word zi (子), for example when it was attached to the Westerners in the term yang guizi (洋鬼子; lit.