Following the laws governed by the government could be divided into three categories,
1. The laws are contrary to what Allāh Taʿālā has prescribed, such as a man giving his wife the power of divorce, giving a daughter the same share of the inheritance as a son, allowing the drinking of alcohol, the taking of interest, and so on. It is not permissible to act upon these laws or approve of them. A Ḥadīth states:
«لا طاعة لمخلوق في معصية الله عز وجل»
“There is no obedience of the creation wherein there is disobedience to the Creator.” (Musnad Aḥmad, No. 1095).
«السمع والطاعة على المرء المسلم فيما أحب وكره ما لم يؤمر بمعصية، فإن أمر بمعصية فلا سمع عليه ولا طاعة»
“It is necessary upon a Muslim to listen to and obey the ruler in all matters, as long as one is not ordered to carry out a sin. If he is commanded to commit a sin, then there is no adherence and obedience.” (Sunan at-Tirmidhī, No. 1707)
2. The laws are in accordance with what is mentioned in Islāmic teachings. In this case, one must abide by them, intending the obedience of Allāh Taʿālā and His Nabi (Ṣallallāhu ʿAlayhi Wa Sallam).
3. The Islāmic texts have not said anything about the laws, but they are in the best interests of the people, such as laws having to do with driving, paying of rates & taxes for services, etc. These laws must be adhered to, in accordance with the Qurānic texts which enjoins being faithful to contracts and covenants. Allāh Taʿālā says: “O you who believe! Fulfill (your) obligations” [al-Mā’idah: 1]. Being a citizen of a country, one has agreed, by default, to abide by the laws of the country; as such, it would be imperative for every person to remain true to his agreement as long as it does not contravene the laws of the Supreme Commander – Allāh Ta’aala.
However, if a law of the country is contrary to Sharīʿah and it is imposed on an individual without him having any choice in the matter, then reluctantly and grudgingly, a person may follow that law out of necessity. For example, it is impractical to live in a country without an Identity Document (I.D.); he will therefore be permitted to make an I.D. even though it entails the taking of a photo (which is generally regarded as impermissible).
A person should endeavor to the best of his ability to practise on the laws of Sharīʿah in the manner prescribed. However, if there is a fear of falling into problems with the authorities and a person does not have the capacity to endure the difficulties of being imprisoned etc., or he fears for his life, then in such a case, he may practise his religious duties secretly, if that is possible.
If a person, however, is unable to practise upon his Dīn at all, then he must make Hijrah – migrate to another country wherein he will not face this problem. Allāh Taʿālā says in the Qur’ān: “O My slaves who believe! Certainly, spacious is My earth (so if you cannot worship Allāh at a place, then go to another)! Therefore worship Me. (Alone)” [al-ʿAnkabūt: 56].
The sole purpose of this worldly life is to worship Allāh Taʿālā. As such, if a person is unable to fulfil his duties to his Master, he will have to forgo and sacrifice some of his worldly luxuries and pleasures, and at times, his hometown and close associates in order to fulfil this objective of his.
The best precedent we have of this was Nabī ﷺ himself. Nabī ﷺ left the Holy Land of Makkah Mukarramah wherein he was born and raised, and migrated to Madīnah Munawwarah. In Madīnah Munawwarah they were at total ease in worshipping Allāh Taʿālā. Similarly, the Ṣaḥābah Radhiyallahu Anhum migrated to Abyssinia, simply so that they may practise on their Dīn. Therefore, if we find ourselves in a similar situation, we will be bound to migrate to another city or country wherein we can freely practise on our Dīn.