Connecting 12V fan to LM317 DIY PSU circuit
It's a bad circuit that you are trying to fix. Use a smaller DC voltage to feed the LM317 then it won't get anywhere near as hot. Currently, with 25 volts in and 12 volts out, the LM317 is "dropping" 13 volts and, if the load is (say) 0.5 amps, that's a power loss in the LM317 of 6.5 watts and it will get even higher under heavier loading conditions.

So, my advice is choose a more suitable transformer with an output AC voltage of about 12 V. Then you will probably have enough spare power capability to run the fan from a regulated 12 volts provided by another LM317.