Hijab is a duty Allah Almighty prescribed for the Muslim woman, and she has to carry out that duty in compliance with the order of Allah, and showing her sincere faith in Allah, for He says: (And it becometh not a believing man or a believing woman, when Allah and His Messenger have decided an affair (for them), that they should (after that) claim any say in their affair. ) (Al-Ahzab 33: 36)
So, it is clear that Allah Almighty has obliged Muslim women to wear hijab in order to preserve them from bedizenment which would definitely make them prone to harassment and render them an easy prey for depraved men with lusty motives. This means that hijab is a means of protection for women’s honor and dignity.
Shedding more light on this issue, we would like to cite for the following by the eminent scholar late Sheikh Muhammad Mitwalli As-Sha`rawi, may Allah bless his soul, in which he states:

Whoever embraces Islam has to accept its rules even if they pose restrictions to his freedom since such rules are set only to benefit mankind. Allah Almighty, the Lawgiver, knows our nature more than we do.
Definitely there is no religion without rules binding on its adherents and followers, so the deviation we see nowadays relates to man’s following his self-inclination; this sometimes drives him to worshipping idols or sun or anything else in his pursuit to lead a life where he will not be subject to any rules.
Logically, if a woman finds hijab as restricting her liberty and, thus, goes about displaying her body to seduce men or snatch another woman’s husband (thus ruining a serene and peaceful marital home), she should not be surprised if her son or husband happens to be the victim of another woman’s foul play.
Hence, the wisdom behind prescribing hijab as a duty for women is to safeguard and protect the whole society from temptation and secure the stability of marital lives.
In the following verse, Allah Almighty prohibits women from revealing their adornment in the presence of marriageable males: (And tell the believing women to lower their gaze and be modest, and to display of their adornment only that which is apparent, and to draw their veils over their bosoms, and not to reveal their adornment save to their own husbands or fathers or husbands’ fathers, or their sons or their husbands’ sons, or their brothers or their brothers’ sons or sisters’ sons, or their women, or their slaves, or male attendants who lack vigour, or children who know naught of women’s nakedness. And let them not stamp their feet so as to reveal what they hide of their adornment. And turn unto Allah together, O believers, in order that ye may succeed.) (An-Nur 24: 31)
Persons mentioned in the above verse are women’s maharim (unmarriageable males), in the presence of whom she is permitted to take off her veil since she could not be harassed by them with lusty motives.
Allah Almighty prohibits women from even stamping their feet to reveal their hidden adornment: (and let them not stamp their feet so as to reveal what they hide of their adornment… ) (An-Nur 24: 31)
Despite all this, some people still consider hijab as a restriction to woman’s freedom, unaware of the fact that it greatly protects her to the extent that had Allah Almighty not commanded her to wear it, she should have called for it. Besides, a woman’s beauty is something temporary, which will, after some time, start fading away, with her husband maintaining his youthfulness and vigor, and perhaps, nourishing hope of taking another wife. Being seduced by an unveiled woman may turn the husband against his wife, thus putting his marital life at stake.
Beauty is a kind of quality that the more one sees it the less captivating and enchanting it becomes; it is only absence that makes the heart grow fonder. Parents may not notice any development in their child due to seeing and having him around all the time, but on staying away for some time, they will definitely notice change in him on seeing again.
A husband may not observe the gradual loss of his wife’s beauty as he daily sees her; on the contrary, she will still remain in his eyes the beautiful bride whom he married many years ago. Yet when he goes out and sees those younger and prettier girls exposing their beauties outdoors, this may injure his self-esteem as he tries to notice variation in beauty (the thing that would not happen had all women adhered to the rule of hijab).
It is so strange that many women are not aware of such a wisdom behind ordaining hijab. It is just for their own sake; to safeguard their marital homes.
Punishment, as far as religion is concerned, never comes unless sin is committed. For instance you have the right to enjoy the beauty and the fragrance of a flower without blame unless you stretch your hand to cut it (trespassing on the right of its owner). You could also contemplate the beauty of a pretty mare without blame unless you try to ride it without the permission of its owner. The same applies to all kinds of beauty on the surface of earth, (And horses and mules and asses (hath He created) that ye may ride them, and for ornament. And He createth that which ye know not. ) (An-Nahl 16: 8)
The above Qur’anic verse permits anyone to enjoy these adornments, either their owners or any others who would like to contemplate their beauties. Thus, it is permissible to contemplate all kinds of beauty on earth except starring at opposite sex. It is not permissible for a male to look at a female other than his wife and the same applies to females, they are not allowed to gaze upon males and contemplate their masculinity. Allah says: (And tell the believing women to lower their gaze and be modest. ) (An-Nur 24: 31)

Thus, it is clear that hijab was meant to protect the Muslim woman, Muslim homes and Muslim society as a whole. It is Allah Himself who created man and woman, and He knows what is beneficial to them and what is harmful.