It's true that Kazakhstan was the last Soviet Socialist Republic to declare independence, but it's not really true that the Kazakh SSR was the USSR for a few days. Mikhail Gorbachev was still in Moscow working as the Soviet President, in charge of a Soviet government, to the end of the month. I go into further details of what happened in the few days prior to the Kazakh declaration of independence in an answer I wrote here.
As for why the Russian Federation gained the UN Security Council seat (and control of the Soviet nuclear arsenal, as well as responsibility for Soviet foreign debt), I go into that situation a bit here. In short, it was part of the agreement negotiated between 11 of the former Soviet Socialist Republics in the Alma Ata Protocol and signed on December 21, 1991.