In the 1898 edition of Brewer's Dictionary of Phrase and Fable it says
"The judge puts on his black cap (now a three-cornered piece of black silk) when he condemns to death, in sign of mourning. This sign is very ancient. �Haman hasted to his house mourning, having his head covered� (Esther vi. 12). David wept �and had his head covered� (2 Samuel xv. 30). Demosthens went home with his head covered when insulted by the populace. Darius covered his head on learning the death of his queen. Malcolm says to Macduff in his deep sorrow, �What, man! ne�er pull your hat upon your brows� (Macbeth, iv. 3). And the ancient English, says Fosbroke, �drew their hoods forward over their heads at funerals.�