There's a possibility that after Sirius's death, Harry just sort of took over. He had already spent time there and knew the place well. The remaining members of the Order of the Phoenix, seeing his connection to the place and his leadership potential, supported his claim to Grimmauld Place.
Perhaps he discovers the planet during one of his adventures. He could be using a new spell that accidentally transports him to this uncharted planet, and then through some series of events, he becomes the rightful owner. For example, he might save the planet from a great evil and as a reward, the planet's native beings make him the owner.
Perhaps he uncovers some major corruption or inefficiency in the Ministry. So, as a result of his efforts to reform it, he is given control. For example, if he finds that the Ministry has been misusing magic for personal gains, he could lead a movement to take it over and run it in a more just way.
He might have discovered the island during one of his adventures and claimed it as his own. Since there was no one else on the island at the time, and he was the first to set foot on it and recognize its potential, he decided to make it his property.
Maybe he inherits it. In the wizarding world, there could be some old family connections or a will that passes the ownership of the bank to him.
One key event could be Harry exploring the secrets of Grimmauld Place. He might discover hidden rooms or artifacts. Another could be him hosting Order of the Phoenix meetings there, which would involve a lot of strategic discussions and planning against Voldemort.
He will most likely meet Sirius Black. Sirius is an important figure in Harry's life and his presence at Grimmauld Place is quite significant. They could have a deep conversation about Harry's anger and what to do next.
Well, in some fanfictions, Harry Potter might come to own the Ministry of Magic through his heroic deeds. He could have defeated a great evil that threatened the wizarding world so severely that the wizarding community decides he is the most fit to take over and reform the Ministry.
She might start by exploring the place. In the fanfiction, Hermione could be spending her time reading the old books in Grimmauld Place. The dusty tomes might hold secrets that keep her occupied and her mind off her loneliness. She could also start cataloging all the magical items in the house. This would give her a sense of purpose and also help her learn more about the wizarding world's history. Another way she could cope is by trying to communicate with the house elves. They might not be the best company at first, but she could try to understand their culture and in the process, not feel so alone.
It could be a magical deal. There might be a spell or a magical contract that somehow transfers the ownership of Grunnings to Harry. This could be part of a larger plot where some magical entity wants Harry to have a connection to the muggle world through Grunnings for some grand purpose, like unifying the two worlds or preventing some dark magic from affecting the muggles.
In the fanfiction, it's possible that the castle was given to Harry by a powerful magical being. This being recognized Harry's pure heart and his need for a place of his own. Or perhaps Harry won it in a magical contest. He had to overcome many challenges and prove his worth, and as a result, he was granted ownership of the castle.