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.