After the Russian Revolution
There were a number of reasons behind the move
The foreign threat: the proximity of Petrograd to German, Finnish, or Baltic areas was too much of a security risk especially given the parlous state of the Red Army.
Infrastructure: Petrograd was not a self-sustaining city in wartime conditions. It was hard to supply grain to the city and this created the urban unrest that sparked the February Revolution. Additionally, the rail lines within Moscow and its factories were essential to maintain inner lines of communication during the Civil War.
Ideology: Moving to Moscow was congruent with a number of Bolshevik prerogatives. Unlike Petrograd, Moscow was the major industrial center of the tsarist state. Therefore it had the largest working class population and thus would be a suitable capital for Bolshevik state.
Politics: Although the Bolsheviks had gained much political ground within Petrograd, the urban politics of the imperial capital were constantly shifting. While the Bolsheviks had success in cultivating the support of the Petrograd Soviets, they never had full control over them. Moscow's support for the Bolsheviks was much more stable and less conditional than in Petrograd.
hi! you might be interested in responses to these related posts
Why did the capital of Russia move from St Petersburg to Moscow?
When and why did the Russian capital become Moscow, as opposed to Peteograd?