What are the factors that lead to this divergence in outcomes between USSR and China?
You might be interested in this answer I wrote on Gorbachev's reforms and how they led to the fall of the USSR.
Some points I can add onto that (with the warning I know the Soviet story much better than the Chinese one): Gorbachev was never trying to transition to capitalism. His attempts at reform were very explicitly to reform and improve socialism in the USSR, and spur it to close the gap in living standards between it and Western countries. The term often used was "uskoreniye" or "acceleration", and the focus was on improving productivity through such measures as an Anti-Alcoholism campaign, anti-corruption campaigns, and attempts to make Soviet government and party leaders more responsive to people's need (more on that below).
Gorbachev did institute some reforms that allowed greater freedom of action at the enterprise level, such as the Jan. 1988 Law on State Enterprises, and also liberalized rules around private enterprises with the May 1988 "Law on Cooperatives", and while these were major reforms, they did not fundamentally restructure the Soviet economy: ie there was still Central Planning, and most enterprises were state-owned and funded with "soft" budgeting. These laws did begin to seriously unravel the Soviet economy - the private cooperatives were often formed as "consultants" in connection with state enterprises, and as such would work to convert those soft state credits into hard currency, ideally foreign currency. Yet they didn't really replace the socialist system with a market system. Gorbachev in 1990 noticeably stepped back from the implementation of a market system as laid out in Grigory Yavlinsky's "500 Days Program", and the result that the Soviet economic, wracked by inflation and widespread shortages, became something of neither one nor the other. Big market reforms would have to wait until Boris Yeltsin won over power from Gorbachev, starting with across the board price liberalization on January 2, 1992 and freedom of trade without state permission on January 29, and including measures such as ending "economic crimes" and, perhaps most infamously, the mass privatizations of the 1992 Voucher Program and the 1995 "Loans for Shares" program/scandal.
So what were the big areas of focus in Gorbachev's reforms? I hinted above, much of it was reform of the Soviet government and Communist Party itself, to both attack widespread corruption but to also shake cadres from hidebound ways of thinking. Part of the idea here was that the political system would be more open ("Glasnost"), allowing government and party officials to be criticized in the press (notably for corruption), and for political reforms to provide more competitive elections as a means of holding them to account (although it should be noted that these elections were multicandidate but not really multiparty elections, and were relatively convoluted affairs to boot). The political reforms, however, opened up more political divisions as the republics warred with the union center over who had the most say in controlling state resources, and to boot nationalist movements developed, especially in the Baltics, Western Ukraine, Moldova and the Caucasian republics, which did actually challenge the local communists' hold on power. 1989-1991 in particular became a highly chaotic period that ultimately resulted in the Communist Party banned, and Gorbachev resigning from his office of Soviet president.
One important final note, in direct comparison with China - in many ways China had more freedom of action to experiment with different reforms, in part because it was considered a bit further back on the trail of Marxist socio-economic development from the USSR. The Soviets were supposed to be living in a showcase of "developed socialism", and had been promised by Khrushchev to be living in full communism by 1980, although that promise was quietly dropped and officially forgotten after his time. To try deeper market reforms would be to admit that the Soviet experiment was actually a failure in a way that the Chinese leadership didn't need to worry about (the Chinese Communist Party could always claim that they needed to just back up a bit to more properly work through the capitalist stage of development). One particular example I'm aware of is the Chinese agricultural reforms implemented in 1979, which established private plots and more market mechanisms for farmers to grow and sell crops. Gorbachev, despite being an expert on Soviet agriculture and its drawbacks, explicitly rejected any reforms along these lines, in no small part because he felt that Soviet agriculture, with its ever-larger amalgamated cooperative farms and its vaunted tractor stations, was too modern and too mechanized to institute a system used by Chinese peasants.
A big issue therefore is that in 1985, China was still an incredibly poor, mostly agricultural country, and very far from the industrial and urban powerhouse it is today (it actually only became majority-urban in 2012). The Soviets frankly felt that they didn't have anything to learn from a country like that, and China being a hostile, almost-heretic socialist state didn't help matters much either.