Since this has basically never happened before let's rule out the possibilities.
- It's not due to a hack
- Your cartridge is legit
If those are true then the only feasible possibility was that it glitched. It's not that far fetched since you claim that you were running around pressing random buttons and I'm no expert but that looks like it could put a significant amount of strain on your game. Normally that would lead to a damaged game but absurdly, it led to 300 ultra balls.
The other possibility is that you always had 300 ultra balls and had temporary memory loss
There really isn't any other way to answer this question because the conditions are too unclear and we don't know what variables caused the reaction, whether it be the sequence of actions your character commited or the buttons that you pressed. This is about as coherent of a response you will get
I hope I helped and even if I didn't atleast you have ultraballs