Why has President Erdoğan threatened the UAE when Turkey itself has diplomatic relations with Israel?
As the article you link to in the question alludes to, Turkey's conflict with the UAE runs deep. Particularly notable is this bit: "Turkish officials have accused them of offering financial and logistical support to the PKK terror group to carry out attacks in Turkey." So, criticizing the UAE about Israel may not really be about Israel at all.
It's also worth nothing that, Turkey has had relations with Israel since 1949, in a very different world. But the relationship is often tense. It's a lot easier for Turkey to show displeasure with Israel by criticizing UAE then it is to take the more radical step of breaking relations with Israel.
I don't expect you will find anyone in the Turkish government offering any direct explanation for the apparent contradiction, but I think these two points together do make it somewhat easier to comprehend where they may be coming from.