For the initial seven years of his government, Mr. Erdoğan built up Israeli ties, economically and other. During those times people's religions were the same as they are now. It is nothing to do with religion. Hamas is elected body of palestenians, so he supports aggrieved palestenians in their just cause.
from the article: Turkey PM consoles Hezbollah leader over top Shi'ite cleric's death