As Valorum already pointed out in a comment, there aren't many official sources on the matter. We can only point out some inherent contradictions:
First, it was mentioned that the description for the Coin trophy in the Super Smash Bros franchise is
The Mushroom Kingdom is dotted with these mysterious coins. There seems to be an endless supply hidden in various blocks, and Mario gains an extra life when he manages to collect a hundred of them. No one can confirm whether or not these coins are actually used as the currency of the Mushroom Kingdom, but it's a safe assumption
By the time the first Smash Bros on the N64 game came out, this very line had already been partially proven false: in the SNES Mario RPG game coins are indeed used as a currency and can be used to buy items at most shops. That has been a staple in almost every Mario rpg after - both in the Paper Mario and in the Mario&Luigi series. The original Mario & Luigi: Superstar Saga game even mentions currency exchange rates between the Mushroom coins and the Beanbean coins.
Also worth noticing is that even if you consider the RPG Mario games to be part of an alternate continuity (after all, Paper Mario world is shown to be an alternate dimension to Mario&Luigi one - see Mario & Luigi: Paper Jam) coins are also used to buy items / play minigames in some of the main series Mario games:
- coins are used in the Bonus Chance minigame in Super Mario Bros 2. Since this game is actually a "character swap" of a different game one could argue it shouldn't be considered, but the events in the game have actually been canonicalized.
- again, they are used to play a minigame in Super Mario Land 2.
- they can be used to buy Chance Cubes in Super Mario Galaxy 2.
Leaving the currency problem aside for a moment, let's just focus on the "coin source" problem. Again, consider the quote from the WarioLand 4 game manual (thanks to Valorum for finding it)
"For some reason, Coins appear when you smash enemies! Don’t think about it too hard, Einstein! There are some supernatural phenomena in the world that just can’t be explained!!”
This points out to the fact that defeating enemies gives out coin. It actually gets better: in Wario Land: Shake It! (which to be fair takes place in an alternate dimension) you can get coins just for shaking enemies! Arguments can be made that the Wario series isn't probably canon with the main games (but remember - the first WarioLand game IS Super Mario Land 3!) so probably we should just avoid taking Wario games in account.
... but defeated enemies already dropped coins in the main game series!
Starting with Super Mario World and onward multiple games had enemies drop coins when defeated. In World, they drop a coin when it by a fireball - interesting enough this feature was ported back to Super Mario Bros 3 in one of the many remakes.
From that point on, things start to get even crazier, to the point almost everything can now give out coins:
- defeating enemies by almost any means give out coins in most 3d Mario games.
- block can be turned into coins by using special P-Switch blocks (the reverse is also true).
- bonuses can generate coins - the Gold Flower New Super Mario Bros 2 turns blocks and enemies into coins, the Gold Block from the same game gives out coins just by moving around
- in New Super Mario Bros 2, even some enemies join the "coin producers" club: both Gold Lakitus and Gold Bro use coins as a weapon. Or at least, they try to... since Mario can just grab those coins with no harm.
and that does not even takes in account even weirdest thing like coins appearing in Smash Bros levels (not smash coins, actual MARIO coins), powering karts with coins in Mario Kart, the fact that a coin is worth 5000G in the original Luigi's Mansion games (only to retcon that later in the second game where a coin is worth 1G), regional Kingdom coins in Mario Odissey, the fact that multiple types of coins exist (red, blue, purple, Dragon, FROG, Star, Ace...), Toads apparently receiving a coin salary in some Mario comics and so on...
In the end, I fear this is best left alone. As Wario said, the coins are there: just grab them and ask no question.
... Or you could just do like I do and assume Doom Guy is the one placing coins trough all levels, in return for Mario being the one that places health potions along the corridors in Doom maps...