Why does Turkish Airlines avoid Israel when going to Amman, but not on the return leg?
There are no issues overflying Israel to Jordan:

From the Israeli AIP:


Prior permission is not required for commercial scheduled
flights by aircraft registered in countries that are parties to the
International Air Services Transit Agreement (IASTA) or
where the relevant Israeli bilateral Air Services Agreement
allows overflying the State of Israel or making stops for non-
traffic purposes.


The prohibited airspaces on the shorter route allow flights above 6000 feet (per the AIP).

There are two airways that are used. Each is one-way.


(skyvector)

Amman arrival procedures allow flights coming via waypoint SALAM on the Israeli side (the OSAMA arrival). See SALAM and OSAMA above.



The AIP confirms airway P51 (eastbound to Jordan) is used.



There is a whole section titled 'Procedure for IFR flights to and from Amman (Jordan)', nothing stands out, just to have two-way communication established with both ends.

As far back as flightaware allows, it's consistent. So that rules out airspace closure for military exercises, etc., and also similar threads exist on airliners.net as far back as 2012.


Conclusion:
What all that hints at, is that the reason is in the fine print of the non-publicly-available air service agreement between the nations and carriers involved.
Note: the site that hosts the eAIP of Jordan is not loading, so I couldn't check the Jordanian side.
Also, it's not a diplomatic thing: Pegasus Airlines 1710 (Turkish) and Royal Wings 6558 (Jordanian) when flying from Turkey to Amman, overfly Israel (shown below).