Kreacher was never not owned by Sirius - he just creatively interpreted his orders.
When he leaves 12 Grimmauld Place, Kreacher is still owned by Sirius - he just interpreted Sirius’s order to get out to mean leave the house, and went to Narcissa.
“How?’ said Harry blankly. ‘He hasn’t been out of Grimmauld Place for years.’
‘Kreacher seized his opportunity shortly before Christmas,’ said Dumbledore, ‘when Sirius, apparently, shouted at him to “get out”. He took Sirius at his word, and interpreted this as an order to leave the house. He went to the only Black family member for whom he had any respect left … Black’s cousin Narcissa, sister of Bellatrix and wife of Lucius Malfoy.’
‘How do you know all this?’ Harry said. His heart was beating very fast. He felt sick. He remembered worrying about Kreacher’s odd absence over Christmas, remembered him turning up again in the attic …”
- Harry Potter and the Order of the Phoenix, Chapter 37 (The Lost Prophecy)
Kreacher was indeed forced to obey Sirius until his death, but since he felt no true loyalty to him, he also sabotaged the Order’s plans for Narcissa, who he respected as a proper Black.
“Kreacher is what he has been made by wizards, Harry,’ said Dumbledore. ‘Yes, he is to be pitied. His existence has been as miserable as your friend Dobby’s. He was forced to do Sirius’s bidding, because Sirius was the last of the family to which he was enslaved, but he felt no true loyalty to him.”
- Harry Potter and the Order of the Phoenix, Chapter 37 (The Lost Prophecy)
Since Kreacher never was freed from Sirius’s ownership of him, it passed to Harry because of Sirius’s will.