This is because the French language generally assigns gender to countries based on their endings.
* Masculine endings: -ique, -an, -e, -o, -au, -eu
* Feminine endings: -ie, -ée, -ue, -a, -s, -x
Since "Iraq" ends in a consonant, it follows the masculine rule.