If the causal sentence (= the sentense which starts with "επειδή" or "γιατί") comes after the main clause, "επειδή" or "γιατί" can be used interchangeably. "Επειδή" is a bit more formal than "γιατί." "Γιατί" is more common in oral speach, because it is shorter (γιατί"has 2 syllables, "επειδή" has 3 syllables")
Δεν ήρθε επειδή είχε δουλειά. = He didn't come because he was busy.
Δεν ήρθε γιατί είχε δουλειά. = He didn't come because he was busy. (less formal)
Επειδή είχε δουλειά, δεν ήρθε. = Because he was busy, he didn't come.
In this phrase we cannot put "γιατί" instead of "επειδή."
When "γιατί" is the first word of a phrase, it always means "why"
Γιατί δεν ήρθες; = Why you didn't come?