做人不作亏心事，夜半敲门也不惊. Be (a) person (that) does no heart-deficit acts, (even) midnight knock on (your) door (brings) no fear. (SY2)
(By negative implication: Only those who do evil need worry that bad things will happen to them when unexpected.)
Westerners make a distinction about head and heart, reasoning vs. passion. The Chinese places both on the heart, seeking guidance from it on both ethical and emotional matters. Thus the concept of 问心, or “ask (your own) heart” for ethical guidance in one’s conduct and dealings with others. The aspiration is to be 问心无愧, or “ask (your own) heart (and) not (be) shameful.” That is, conduct yourself according to a commonly accepted set of ethics, and do not do things that will bring shame. Culturally, this “heart” encompasses much more than the natural instincts that one is born with. You ask your heart for guidance, but that Chinese “heart” is expected to encompass all societal ethics (in context, inclusive of all the 10 Biblical Commandments and more).
What is this 亏心 (pronounced “kui xin”) business? What is the “heart deficit” deal? This brings in the concept of Chinese spirituality. The Chinese, I believe, are more pervasively spiritual than deeply so. Most naturally assume that there is one or more higher being keeping score, or at least a ledger, of EVERYTHING that a person does or says. In this ledger, if you do good things, that will bring good karma (either in this lifetime as good fortune, or the next life through reincarnation as a higher class of being, such as being born a rich human). If you do or say evil, that will bring bad karma. That explains the 亏, or “deficit” part – do and say good so your karma ledger is not in deficit.
So that explains the first part of the 14 syllable saying. What about the 2nd half? Well, before the modern advent of electricity, folks go to bed early. And I mean really early, as candles and oil lamps are too expensive to operate for most Chinese. Most of them (over 90%) were illiterate, being rural farmers, so there was no serious need for lighting. Entire villages go to bed shortly after dinner, and there is little socializing after dark. So a knock on the door at midnight often mean that something serious (or bad) had happened.