Voltage Regulator Poor PErformance
Your regulator dissipation is about 14 Watts - you'd need a significant heatsink to handle that.
Power = V x I = (12-5)*2A = 14W.
Without a heatsink "you haven't got a show" to use technical language :-). 

The datasheet table 7.5 page 6 shows the thermal resistance in C/W for the T model regulator as 23 °C/W, - say 25 ° C/W, so say 100C rise you'd need a C/W = delta_T/Power = 100 / 14 ~= 7 C/W heatsink. That's a largish heastink. 

If you add a series resistor in the input you can dissipate most of the heat in the resistor. The 317 needs about 3V drop / "headroom" at 2A (IF your version will handle 2A) (see datasheet)   

To give the 317 3v headroom for regulation 

Vdrop_R = (12-5-3) = 4V
 R = V/I = 4/2 = 2 Ohms.
Limit is when Vout is 5V at full load.

Power reg is now about P=V*I = (12-5-4) x 2 A = 6W so you STILL need some sort of heatsink.  For 100C rise Rth_sink ~= 100/6 = 16 C/W

The resistor power dissipation is about V x I = 4v x 2A = 8W.
So use 10W minimal and better 20W.
2 x ceramic 10 Watt air cooled cheap would work well.



THIS SE Q&amp;A will tell you more than you want to know about regulator overheating