If a woman refuse to wear hijab, is it allowed to inprison her or give her s legal punishment according to sharia?
There is no prescribed punishment but a Ta'zir can be given for it. A Ta'zir is legal punishment that is given for committing any sin for which there is no Hadd or Kaffarah in Shariah, that is abstaining from an obligatory act or committing a forbidden act.
التعزير هو مشروع في كل معصية ليس فيها حد ولا كفارة
Ta'zir is prescribed for every sin for which there is no Hadd or Kaffarah
This comes under enjoining good and forbidding wrong, which is foremost the duty of the state.
الذين إن مكناهم في الأرض أقاموا الصلاة وآتوا الزكاة وأمروا بالمعروف ونهوا عن المنكر
Those who, if We give them authority in the land, establish prayer and give zakah and enjoin what is right and forbid what is wrong.
Doing so has different stages, at first the offending person would be informed of their sin, then advised softly, then reprimanded, then warned, then a punishment would be given such as imprisonment, lashing, fine, exile and even execution depending on whatever the judge considers appropriate depending on the case.
The sentence of punishment without hijab and bad hijab is in accordance with the meaning of some verses of the Holy Quran, it is stated in Surah Noor. “Those who like to spread indecency among those who believe will have a painful punishment in this world and the hereafter, and God knows while you do not know.”"Those who want ugliness to spread among the people by faith is a painful punishment for them in this world and the hereafter, and God knows and you do not know." (Surah Noor, verse 19) Since the lack of hijab is the basis for the spread of prostitution and corruption in society and has destructive effects on families and society.
Therefore, since one of the things that pollutes the atmosphere of the Islamic society is the non-observance of Islamic dress, and in fact, the lack of hijab, since it spreads corruption in the society, is a great threat to the mental security of the society and its consequences. To the detriment of society, the Islamic government is obliged to fight against this threat. Keep it healthy and ready for the growth and excellence of its people.