I believe the answer to this is data mining. As every game is made of code, the code can be read or accessed via special software. Usually this is done by experts in the field who are themselves knowledgeable of how various games are coded. Upon the release of any game, these data miners go through the code to figure out how things work. This is the reason we know the complex formulae behind whether a Pokeball will catch a Pokemon, whether your Pokemon can successfully run away from a wild encounter, and so on.
Many amateurs and hobbyists buy new or used cartridges and try and reverse engineer them. This allows them to figure out things that can't be otherwise identified.
Aside from that, developers themselves get beta testers and hackers to purposely try and break the game, to identify and patch any glitches before the games are commercially sold. This is to prevent some hacker to gain an unfair advantage in competitive gameplay, simply by having "ethical hackers" do it for the sake of fixing and understanding them before hand. Of course, there are many glitches and bugs that slip by and are later exposed and patched, but for the most part a regular player would be unable to break the game. This process also gives access to source code, which if leaked, could be used for data mining.
Developers keep trying to make it tougher for non legitimate hackers to data mine through various safety features, which are more secure now than in the previous generations, as they are worried that data mining of the game and the console allows the creation of roms and emulators respectively, which are essentially pirated products.
In some rare cases, developers themselves leak a part of the code so that the leaks generate hype for the game and act as free advertising. This isn't as common, but is still an observed phenomenon across various games.
As for why certain Pokemon even learn certain moves before they can evolve? There's a number of reasons, including but no limited to: Having events where low level Legendary or other strong Pokemon are given out, or to force players to use items like the Heart Scale to gain access to otherwise inaccessible moves, and so on. By having the Pokemon learn moves at level 1, they also patch a possible bug where a hacked low level Pokemon (like a level 2 Charizard) would be sent out to battle and behave erratically due it not having any moves whatsoever.
These are some of my assumptions and conclusions I've drawn from seeing a few data mines and leaks across the years on Twitter, 4chan, and the like. It's possible I've made some incorrect assumptions based on what I've seen, and I'd appreciate any corrections to the same.