If yes, what would the punishment likely be? Were these laws same(as restrictive) for both sexes?
If no, would I get a different treatment in the society on account of being dressed alike to the upper class?
[A caveat that this answer applies most specifically to Early Medieval England]
Would the law at the time prohibit me from wearing such an expensive dress
Quite the contrary! It's worth pointing out to start with that the idea of buying "a dress" is a very modern phenomenon. While you'd be able to buy pre-made accessories (souces suggest that milliners were an established profession and it was possible to be pre-made cloaks and hoods) for the majority of clothing, you would instead purchase the fabric and then construct the dress yourself or, if you had money, pay somebody to make it for you. Money is of course a barrier to obtaining the more sought-after fabrics - silks, velvets etc - or heavily embroidered wool, but the biggest barrier is time. Fashion historian Bernadette Banner recreated a 15th century high-end gown using contemporary methods (you can see videos here) which took 250 hours of sewing to produce; a considerable investment of time or money. As a wealthy early medieval English woman, you might have had the luxury of a slave specifically to do your tailoring: in one notable tenth century will, a woman leaves her daughter a slave who is noted to be a valued seamstess, as well as her spinning wheel and other equipment. As a poor peasant woman, we might have to assume that you sewed the garment yourself, probably over the course of multiple evenings in between your various other duties, so if nothing else the finished garment would be regarded as a testament to your dedication and - assuming you made a good job of it - your skill. Basic fashion across the early middle ages was seemingly fairly universal; signifiers of wealth and status came not so much from the cut of a gown itself, but in the quality of its materials and construction, and the layers of extra ornamentation and decoration. Most women would have worn a simple kirtle over which was draped a gunna or gown of some variety, and wealthier women would have accessorised this with a mantle worn around the shoulders, the more decorated the better. Men's fashion favoured tunics to around knee length, usually combined with leg-wraps and cloaks in heavier weather, or robes for those in senior or clerical positions. Biographies of Henry I note that when he went to war with his brother Robert over Normandy, he exchanged the long hair, beard and robes of an English king for the close-cropped hair and short tunic and hose garb of a Norman warrior.
Early Medieval English society wouldn't condemn you for wanting to look wealthy; it practically encouraged it. Visual displays of ostentation were fashionable, and much like trendy shoppers chasing brands today, people wanted to emulate the look of the rich and famous. You may already be familiar with elements of high-status English decorative metalwork such as that found in the Staffordshire Hoard, of gold, often inlaid with rubies or other precious stones, but while those items are exceptional, the designs themselves or similar ones were fairly commonplace. Of the early medieval brooches listed by the Portable Antiquities Scheme, for example, only a small handful are silver or gold, but the vast majority feature similar designs but made from copper alloys, which could be burnished to give a gold-like appearance, or coated with a very thin layer of gold leaf. Other finds suggest that cut glass backed by foil was used to imitate the appearance of precious stones in everyday items like brooches or seax handles. Strap ends are particularly interesting finds: buckled belts became unfashionable in around the 7th century, and instead people tended to wear flaxen belts knotted around the waist, often with highly decorated metal end caps. Straps would have been used to carry knives, bags, purses and the like, so strap endswere very common elements and form a vast corpus of archaeological finds, usually turned up by detectorists. Most are highly decorated with intricate patterns; from the late 8th century, the 'Trewhiddle' style featuring curved geometric designs combined with animal motifs becomes fashionable in Wessex, and by the early 10th century, also become fashionable in Mercia, as well as in East Anglia and Northumbria as these areas fall under West Saxon political and cultural influence. Again, while artefacts are known in gold and silver, the majority are copper alloy or tin, which suggests that people wanted to follow the fashions of the wealthy as close as possible just within a much tighter budget.
In regards to laws and punishments for dressing above one's social class, the word you're looking for is "Sumptuary Law" which was a class of medieval legislation seeking to regulate spending, commodities and behavior. While they were written under the auspices of curbing wasteful spending at all levels, they generally served the unspoken (or explicit) goal of making sure those who were not gentry or noble did not appear to be so. Focusing on England in the context of your question, though other nations have enacted similar regulations, the medieval period covers a wide range of time and England itself had issued multiple versions and updates to its Sumptuary law, starting as early as the 13th century by Edward the II with updates by Edward III in 1336, 1337, and 1363. Various types of sumptuary and similarly themed laws were made throughout the medieval period on through the 16th century. While many of the earlier sumptuary laws were aimed at promoting English made garments, or regulating the diets and fashions of the nobility, these laws are what people associate with maintaining the social divide between classes with language such as:
"no knight under the estate of a lord, esquire or gentleman, nor any other person, shall wear any shoes or boots having spikes or points which exceed the length of two inches, under the forfeiture of forty pence."
Thus, after 1336, it was (on paper) illegal for a peasant to have poulaine style shoes with a 6 cm toe, the remedy for this was a financial fine. Later sumptuary laws in England regulated the types of fur allowed for wear, and the precious metals allowed for buttons on clothing, the value of the veil, clothing you were allowed to wear based on your religion, etc. Exactly what was, and was not, regulated and what the cost of the fine was changes as the laws changed, so further research into the specific (preferably decade) this hypothetical peasant was making this dress and what she was, specifically, making it out of would be required for a more precise idea of whether or not it would violate the law. Generally, the law applied evenly to men and women, though the rules for the woman were based on the social status of her husband or father. However the clothing rules and severity of the fine changed over time, the punishment was always a fine.
The laws were not effective though. They were continually refined, updated, and reissued because people found, as they are prone to do, ways to subvert following the rules. For much of the medieval period money was a way to absolve one's self of wrongdoing, both by purchasing indulgences for religious transgressions or for paying fines as punishment for crimes (or by buying off the criminal charge by paying for the crime to be ignored.) Wealthier commoners, such as successful merchants, influential patricians of the cities, yeomen with large landholdings, etc. could reach an income threshold wherein paying the fine was not only acceptable, but desirable as it was a way to thumb one's nose at the nobility by saying "I'm so much wealthier than you I can afford your clothes, and I can afford to pay the fee when I wear it."
You use the term peasant, which is a broad term which refers to a social class who was predominantly poor, but also included non-nobles who's position or landholdings rivaled and exceeded that of nobles. These commoners were not the norm, and the subsistence existence of most peasants was below a line where saving up to buy the materials for a fancy dress was ever an achievable goal. It is also important to remember the ability of a peasant to acquire wealth increased marginally over time (ie centuries,) and it is no coincidence these sumptuary laws tend to pop up in the century where feudalism begins to erode. These laws were in response to social behavior; enough commoners (but still not the majority) were dressing like nobles before the sumptuary laws which necessitated enacting them to curb what the nobility saw as a societal problem.
Before the 14th century a peasant who was wealthy enough to save but poor enough she did not fit one of these categories of the peasantry which rivaled the social station of the gentry (an exceedingly rare individual) the ramifications of doing so would likely be nothing more than some social friction between her and her peers, as well as between her and her superiors. However, in the late 13th and into the 14th century this began to change and the gray area social status I just mentioned became more commonplace. At this point, the scenario may have created just as much social conflict between her and her superiors, and she would have to budget for paying the fine, but it would be less odd to her peers as a larger percentage of the wealthier commoners were starting to do just what you're describing. In either event, there is no law or record in England of people being ostracized, banned from villages, jailed, or otherwise impacted by dressing above their station apart from the disdain of the nobility and financial penalty.