The coins should most of the times have more value than the material they are made from, as far as i know. So buying raw materials and creating coins should seem to be a good way to generate profit in medieval times and before. So what stopped the people in doing so?
Counterfeiting needs to be considered from two angles. The first is the manufacturing of fake coinage using appropriate raw materials. While a problem this wasn't quite as significant as a second problem, debasement
To one extent or another, coin debasement, or clipping some of the precious metal off and continuing to circulate the coin, had been a problem dating back even farther than medieval times; with Roman coins showing evidence of it as well. Generally one solution that countries have used to address the problem has simply to execute people caught doing it (ex Treason Act 1415). However, that presumes that you can actually catch people doing it and unsurprisingly it is quite hard to do so! So clearly a solution was needed to address the problem.
If you have some loose change, check to see if you have any silver-colored coins and observe the edge. See how it has a ridge or other texture on the rim of the coin? That's called reeding and was the solution to debasement. Simply add something to the rim that will be missing when the coin is clipped and it gets a lot harder to do it. However, this required an advancement in minting coins, which is where we come back to outright counterfeiting them.
For most of history coins were manufactured through literal brute force ^(1) - take a blank piece of metal of the correct weight and material, put it down on a die, put another die on top of it, and smack it really hard with a hammer. The metal then takes the form of what's engraved into the dies and now we have a coin! While effective, the manual nature of the process meant that coins would frequently have a degree of irregularities between each other and the metal couldn't be too hard or you could hammer it. So you tended to have softer coins that would "sweat" silver dust or could be clipped without it being evident.
Since coins were just being hammered, it really wasn't that hard to counterfeit them and while a farmer might not have the relevant skills, a blacksmith or goldsmith likely knew how to do it. Of course the tricky bit here is that the value of the coin was tied to the weight of the coin. So if you could afford to buy a kilogram of gold or silver, there wasn't any financial gain in creating coins of the same weight. Likewise, since the sweating and clipping of coins was a well known problem, merchants would just weigh the coins when you traded with them. So to make a profit at counterfeiting coins, someone would take a low value metal (ex., tin or lead), make a die of a high value coin, strike the coin, and then plate it to pass off as the real thing. Eventually these could be found out simply through the plate wearing off, but a well made counterfeit could circulate for awhile. This was the usual way of counterfeiting coins, but there was enough of a technical challenge in making the coins (i.e., making passable dies, hammering, and plating) that counterfeiting wasn't nearly as common as clipping the coins was.
Clearly a better way was needed and this was known for a long time. Returning to just outright executing counterfeiters, you also see documents showing the Church appealing to the state of people souls to prevent counterfeiting along with other social controls. However, none of it was really effective until the advent of milled coinage in 1550 which used a screw press to apply enough pressure to turn the blank into a coin between two dies. Milled coinage had the advantage of being perfectly round - making it easier to catch clipping - and techniques for reeding were quickly developed as well. By this point the resources needed to counterfeit coins reached the point where profit motivated counterfeiters would turn to something much easier to fake, banknotes.
Source / Readings
Hložek, M., & Trojek, T. (2017). Silver and tin plating as medieval techniques of producing counterfeit coins and their identification by means of micro-XRF. Radiation Physics and Chemistry, 137, 234-237.
Oslanský, F. (2009). European Written Sources on the Counterfeiting of Coins in the Middle Ages. Historický časopis, (Supplement), 3-14.
Porteous, J. (1969). Coins in history. Putnam.
Schaps, David M. "he Invention of Coinage in Lydia, in India, and in China". XIV International Economic History Congress, Helsinki 2006.