On one level, the cause of wars of independence is obvious. Countries fight for independence if they are being ruled by another country. People generally do not like to be ruled by outsiders and therefore they rise up in wars of independence.
But this is too simple of an answer. If this were the only cause of wars of independence, every colonized country would rise up. The countries would do so early in the time that they were colonized and they would continue to do so periodically until they prevailed. This is not how things have historically gone. Why, then, do wars of independence happen at some times and in some countries but not in other times and places?
There are at least two reasons why wars of independence might arise. First, the ruling country might tighten their control over the country they rule. In other words, being ruled might become more onerous for the colonized country. When this happens, the change might set off an increased sense of grievance in the people who are being ruled. This might lead to a war of independence. Second, something might happen to make the people who are ruled feel like they have a decent chance of winning a war if they start it. For example, Mexico’s war of independence started at a time when Napoleon had invaded Spain. This might have made the Mexicans feel that they had a better chance at winning if they rose up at that particular point.
In other words, countries will not start wars of independence at random times. Something has to happen to make them either A) more aggrieved about being colonized and/or B) more confident about being able to prevail in their war.