What is the meaning behind dark works often taking place at midnight?
This is an example of pathetic fallacy, more specifically an empathic environment. i.e. giving an environment a percieved emotion. It is a common literary technique.

Some other examples include:


Rainy scenes when a character dies / delves into depression.
A calm breeze after turmoil has subsided.
A big storm buffets the castle walls as the evil king rages
The sun appears from the clouds as the characters see a new path to follow after being downtrodden
It snows and the land is harsh when a man is exiled from the city. 


In this case, midnight - is commonly associated with spookiness, feelings of unease and the supernatural. 

It also conjures images of darkness, which is commonly associated with evil - where light is usually a good force.