I think, at the end of the day, the root cause comes down to whether the judiciary is truly independent. In theory, Turkey is governed by the rule of law, with a separation of powers and secularism. In practice, however, there’s a deep divide between various subcultures and a significant lack of trust.
YPG has strong ties to PKK, which is recognized as a terrorist organization by NATO and EU [1] [2].
I strongly dislike Erdogan and his policies, and certainly don't approve the attack but YPG is a different issue. It is sad that most outsiders' view about the Kurdish conflict boils down to 'Turkey hates Kurds'. It's just not like that. We should all unite against terrorism.