What is the function of diode D3 in this circuit?
What is the function of D3?

It's a reverse polarity diode. In normal operation it does nothing but, if you incorrectly reverse the supply wires to J1, D3 will short out the wrong polarity supply and hopefully prevent the main circuit turning to smoke. If the 12 volt power supply is too powerful, D3 will also turn to smoke so realistically you should also use a 1 amp fuse.