While Russia opposed a military resolution, its position has always been that Nagorno-Karabakh is legally part of Azerbaijan. For example, Putin publicly stated that Nagorno-Karabakh is part of Azerbaijan in a press conference after the 2020 ceasefire. In a statement on 5 October 2023, shortly after the conflict, Putin stated that Armenia itself recognized Nagorno-Karabakh as Azerbaijani territory (translation mine):
"In Prague in the autumn of 2022, under the auspices of Mr. Charles Michel, French President Emmanuel Macron and Mr. Olaf Scholz, the German Chancellor, the leaders of Armenia and Azerbaijan met. And there they signed a statement, from which it follows that Armenia recognized Karabakh as part of the Republic of Azerbaijan. Moreover, the leaders of the delegation, the leaders of Armenia, explicitly named the territory of Azerbaijan in square kilometers, which without any doubt includes Karabakh. And they stressed that they recognize the sovereignty of Azerbaijan within the boundaries of the Azerbaijan SSR, which was once part of the USSR. And as everyone knows, Karabakh was also part of the Azerbaijani SSR. In fact, the main, absolutely key issue, which was the status of Karabakh, was resolved," the Russian president said.
Putin noted that when Karabakh declared its independence, no one recognized this independence, not even Armenia. "Which, to be honest, is strange to me, but nevertheless, they made the decision not to recognize the independence of Karabakh. But here in Prague, they recognized that Karabakh belongs to Azerbaijan. And then in early 2023 repeated the same thing at an analogous meeting in Brussels. By the way, no one told us about this, I personally found out from the press. But Azerbaijan has always believed that Karabakh is part of its territory," the Russian head of state added.
Putin called the recent events in Karabakh an inevitable consequence of Armenia's recognition of this region as part of Azerbaijan. "Karabakh officially became part of Azerbaijan, this is the position of the modern Armenian state. Well, what should we do?" He said. "Everything that happened in the recent past, 2-3 weeks ago, and the closure of the Lachin corridor and so on, all this was inevitable after the recognition of Azerbaijan's sovereignty over Karabakh. It was only a matter of time before Azerbaijan would establish constitutional order there within the framework of the constitution of the Azerbaijani state." Source
In short, Putin's publicly stated position is that Nagorno-Karabakh was never claimed by anybody to be part of Armenia, that its self-proclaimed independence was never recognized even by Armenia (both of which are true), and therefore that the attacks on Nagorno-Karabakh in 2020 and 2023 were an internal Azerbaijani matter, and never an attack on Armenia at all. Therefore, Russian peacekeepers (as described by Putin later in the statement) were limited to protecting civilians and providing humanitarian aid, and had no grounds to take any further action to defend the territory.
Note that while the Second Nagorno-Karabakh War usually refers to the 2020 conflict, this statement is regarding Azerbaijan's eventual successful conquest in 2023. But this was the culmination of a long-term policy regarding in the Nagorno-Karabakh conflict. For example, in 2020 the Russian Ministry of Foreign Affairs in response to a request from Armenia issued a statement that "In accordance with this treaty, Russia will provide the necessary assistance to Armenia if hostilities spread directly to the territory of Armenia."