Napoleon’s military tactics / strategy was defined by a couple of principles, namely manoeuvrability and “defeat in detail”, which was where you bring as much of your force as possible upon isolated parts of the enemies force (using this was how he had been able to defeat much larger armies in earlier campaigns, such as in Italy). What he always wanted to do was decisively defeat the opposing army or armies. This was the aim of his Russian campaign too.
Napoleon had hoped to quickly meet the two Russian armies opposing him (led by de Tolly and Bagration), and defeat them in detail, which would then, he believed, lead to the Tsar coming to terms with him. However, the Russian armies kept retreating instead, and while Napoleon very quickly advanced eastward, capturing cities like Vilnius and Minsk, no peace terms came from Russia.
Napoleon’s forced marches and attempts to cut off the separate Russian armies in the hopes of defeating them in detail had severely damaged his own army, and by the time he began his march towards Smolensk in pursuit of the Russians, he’d lost about half his effective fighting force. The Russian armies at this point had also been able to reattach themselves to each other. However Napoleon never abandoned the idea of needing to decisively defeat the armies, so continued his pursuit.
Reaching Smolensk the first major confrontation, the Battle of Smolensk, took place, where Napoleon assaulted the fortress city with such force it was essentially destroyed. While it was a bloody battle in itself, the Russian general Barclay de Tolly managed to withdraw the bulk of his army from the city and continue his retreat eastward, so again Napoleon was not able to deliver his desired decisive blow to the Russian armies.
The Tsar and a lot of the Russian high command were furious with de Tolly’s cautious approach, wanting to meet Napoleon in battle rather than retreating. De Tolly was removed from command after his retreat from Smolensk. However, his replacement, Mikhail Kutuzov, determined to continue de Tolly’s strategy, and continued withdrawing farther east, towards Moscow.
At this point there was a fair amount of pressure on Napoleon to stop advancing and solidify their position, but Napoleon, desiring (and in a lot of ways requiring due to the continued fighting going on in Iberia) a more speedy end to the Russian campaign, refused to give up the chase.
He pursued the Russian armies east, and due to pressure on Kutuzov from the Tsar and the Russian high command not to abandon Moscow without a fight, the Russian army finally met the Grande Armee in full force at the Battle of Borodino, the bloodiest battle of the Napoleonic wars. While this battle was tactically a French victory, it was a Pyrrhic victory as the Russian army, while bloodied horribly, was not destroyed, and Napoleon had lost almost a third of his remaining fighting force.
Kutuzov once again retreated eastward, and called for the evacuation of Moscow. Napoleon and his army then moved into it.
It’s worth noting that while St. Petersburg was the political capital of Russia at this time, Moscow was in many ways the cultural / spiritual capital of the country, so its occupation was significant. But Tsar Alexander decided he could continue to resist Napoleon thanks to the survival of the Russian army, and so did not seek a peace deal.
So in short, Napoleon had found himself as the occupier of a (horribly burnt) Moscow, but this had almost been an accident. He had seen the campaign ending well before reaching Moscow, by destroying the fighting ability of the Russian armies. He had essentially chased the Russian armies who kept falling back East all the way to Moscow, rather than had aimed for Moscow as the goal for his army to occupy.