This depends on how much gold you make available in your game, but it most likely is overpowerd
This the Effect of +1, +2, or +3 sticks forever after the sword consumed your gold, this is obvioulsy overpowered, giving you a very rare item for a rare item and 300 gp. If it is only for one fight, the question gets more interesting, but if you use the amount of loot given in the treasure tables for encounters, it is probably still overpowered.
The question is, how often can you afford to buy the +3 effect, to make this better than a normal +2 rare weapon? This is will depend on how much gold the party has.
If you hand out tens of thousands of gp early on, the party will effectively have a +3 weapon, a very rare item, by the time they normally would only have access to a +2 weapon, the rare item. If you hand out little gold, and they only can afford to activate this from time to time, the party will have something that is weaker than a normal rare item. In particular because in 5e, there is (other than in older editions) no functional difference between a +2 and a +3 weapon, beyond the slightly better to hit and damage output. In the extreme case where they have no gold, this does not confer any bonus other than counting as a magic weapon.
It is really up to the DM how much they give out. But you can calculate expected gold based on encounter guidance. If you go by that: according to the rules for pure adventuring, it takes you about 2 or so days in-game time to gain a level, and from level 6 on you make thousands of gp per day. With an average of maybe 3-5 combat encounters per day, you will easily be able to always pay for a +3 weapon. As there are few other good uses of surplus gold in D&D 5e after you get to second tier, there also is little opportunity cost.
Xanathar's Guide to Everything has tables on page 135 that expose the math behind the magic item tables in the DMG. According to this, you would get one major rare magic item such as a magic +2 weapon in tier 2, which spans levels 5-10.1
So effectively at these costs and amounts of gold, by the time you find rare items in the game, this will just give the party a use for surplus gold, and the equivalent of a very rare item instead of a rare one, making this overpowered.
1 The rules in Xanathar's are optional to give you more control, but they make it easier to understand how many rare items are officially suggested at a given tier, from the random tables in than the DMG, than the DMG itself. See the inset box on page 135:
The Dungeon Master's Guide assumes a certain amount of
treasure will be found over the course of a campaign. (...)
The optional system described here yields the same number of items, distributed properly throughout the spectrum of rarity