How does 子 come to mean 'midnight'? Arch Chinese lists the meanings of 子 as 


  son, seed, egg, child, small thing, noun suffix(zi5), midnight, Kangxi radical number 39, 1st terrestrial branch


The meanings of child, egg, diminutive noun suffix etc. are clearly related, but I find it hard to remember that this also means midnight (in particular in the Korean 자정/子正). 

How does 子 come to mean 'midnight'? Is it related to the fact that it also stands for '1st terrestrial branch'?
It is indeed related to the terrestrial (earthly) branches, and in a 24-hour day,「子時」represents the time of day between 11:00 PM to 1:00 AM.「子正」, as noted in the question, specifically represents midnight (12:00 AM).

Unfortunately, there is no convenient mnemonic or etymology that you can use to make a connection between「子」and midnight, but I doubt that midnight shows up very often anyway as a meaning (unless you're into traditional Korean timekeeping?).