Phonosemantic compound. 土 represents the meaning and 黑 represents the sound. Originally written as 黑, which depicts a person whose face has been tattooed.
墨 and 黑 don't sound similar in modern Mandarin due to historical phonetic changes. They were more similar in older Chinese.墨 /*C.mˤək/ 黑 /*m̥ˤək (dialect *m̥ˤ- > xˤ-)/