I can understand all the other former Soviet countries splitting up and emerging as independant countries, but how did Russia form a new government in (as far as I know) a very different political system, immediatly after collapsing?
How did it happen? Did someone just look at the former soviet union and go... "Welp, better make a government" and everyone just... accepted it?
What was the legitimacy of this new government?
First, some links to older answers I wrote that might be of interest:
What happened to the Soviet army and police in Russia after 1991
What happened to the Communist Party and their property in Russia in 1991
What happened to the Soviet UN Security Council membership.
For an add-on - Russia wasn't technically "formed" after the Soviet collapse. The Russian Soviet Federated Socialist Republic was one of the 15 Soviet Socialist Republics in the USSR, and so it was always there as a constituent member republic from the USSR's founding in 1922 to its dissolution. It's a bit like a state in a federal system, but the USSR was what's considered an "asymmetric" federal system: not only was the RSFSR huge compared to the other republics (in 1991 it was more than 3/4ths of Soviet territory and more than half of its population), but it actually lacked a number of institutions other republics had, such as a republican communist party and KGB.
In any case, as the Soviet government rapidly fell apart in late 1991, the RSFSR government more or less absorbed as much of those Soviet departments and institutions as it could, and what was left of the Soviet government ultimately shut down or resigned, with Soviet President Gorbachev resigning on December 25, 1991 and transferring his responsibilities (including nuclear codes) to Russian President Boris Yeltsin. Yeltsin (who had been head of the republican RSFSR government since 1990) was elected to the newly-created office of President of the RSFSR in June 1991, by the way.
Just before Gorbachev resigned, the other soon-to-be former Soviet republics (not including the Baltics and Georgia) had signed the Alma-Ata Protocols, which established the Commonwealth of Independent States (a very loose international organization that replaced the USSR), and recognized the RSFSR as being, in effect, the legal successor to the USSR (assuming its UN seat and strategic control of its nuclear weapons, as well as Soviet debts).
The RSFSR was very quickly renamed to the Russian Federation (as it is known today), but still operated under the (heavily amended) 1978 RSFSR constitution, complete with a Supreme Soviet legislature elected in 1990. This legislature and President Yeltsin entered into a protracted constitutional struggle with each other, that ultimately ended with Yeltsin having the Russian military shell the legislature in Moscow in 1993, and ultimately replace the constitution with a new one (still in force). Major economic reforms were undertaken from January 1992 onwards, but that's another story.