Early forms of 字 place 子, “child”, beneath 宀, a roof or building. In ancient usage the character could refer to bearing or nurturing a child; from ideas of naming and social identity, it later developed meanings connected with written signs and words. The exact path of that meaning shift is interpreted in more than one way, so this drawing stays with the securely visible child-under-a-roof structure.
A piece of culture
The “zi” in hanzi 汉字 / 漢字 means “Chinese character”: hànzì in Mandarin and hon3 zi6 in Cantonese. The 字 tells you that the phrase is about writing, while 汉 / 漢 identifies it as Chinese. You will also meet 字 in 名字, “name”. It is a small character that helps beginners talk about the writing system itself.