Who decided which airspaces not to fly through and how? I was looking at some flight paths, and I noticed that while some airspaces are ignored by planes for "obvious" reasons, like the Ukraine - Russian border airspace.

For example, this flight seems to purposely ignore the Ukraine airspace.

But on the other hand, I found some flight which are not ignoring airspaces which should probably be ignored. Like planes flying over Syrian airspace or over Yemen. These places too are war zones and might have militant groups capable of repeating something like MH-17.

This made me wonder as to who decides what airspaces to not fly over, and what are the criteria to do so?
One major driving factor is whether a permit is required. Many countries in the world require a permit even for overflight.


(source)

Depending on country to country, airline to country and general relations it may be more advantageous for a carrier to get permits in one country than it would be in a close neighbor. Going a bit out of the way (burning extra fuel ultimately) may be less costly than delays related to permit issues, etc.

In some cases there are also prohibited airspaces within a country. This is simply airspace you cant fly over for regulatory reasons (generally security). While some of these airspaces are small, some areas can be quite large in size.

While increasingly a smaller case not all aircraft are equipped to fly through all airspaces. Different regulating bodies may require different gear on board for a given flight. Aircraft may be prevented from entering a given airspace if not properly equipped or certified. 

On any given day routes may be amended for weather or potential weather hazards.

As @mins notes in the comments, this answer covers areas avoided for safety reasons.