Answer
In the Name of Allah, Most Gracious, Most Merciful.
All praise and thanks are due to Allah, and peace and blessings be upon His Messenger.
In this fatwa:
1- The national anthem has to be free from any words or expressions that contradict the Islamic principles.
2- If so, it is permissible to sing the national anthem if there are no musical instruments used. According to a group of scholars, it is permissible to use musical instruments in such cases.
Answering your question, Dr. Muhammad Salama, PhD, Islamic Studies in English, Associate Professor at the Faculty of Islamic Sciences al-Madinah International University (Mediu), states:
Loving one’s country in Islam
One cannot deny the feeling of love for one’s family, tribe, home country, etc. This feeling is not prohibited. But it has to be within the parameters of Islamic principles and Shariah objectives.
All sorts of bigotry and fanaticism based on such feelings are not permissible. The bond of Islam has priority over all other kinds of relations.
The Messenger of Allah (peace be upon him) said, “Allah has removed the pride of Jahiliyyah from you and boasting about lineage. [A person is] either a pious believer or a wicked sinner. People are the children of Adam, and Adam is from earth.” (At-Tirmidhi)
So a Muslim, for example, may not hate or begrudge, let alone to fight, another Muslim only because he belongs to another country or tribe.
Singing national anthems in Islam
As for the national anthem, it has to be free from any words or expressions that contradict the above-mentioned principle. If so, it is permissible to sing it if there are no musical instruments used.
The majority of scholars prohibit the use of musical instruments in all cases. However, according to a group of scholars, it is permissible to use musical instruments in such cases.
Almighty Allah knows best.