I think it was mentioned in KH3, but Xemnas says at one point that when nobodies are separated from their hearts, the people nobodies, being the strongest kind of nobodies, start to rebuild new hearts for themselves. That would explain Roxas being able to be put inside a replica (and also how Xemnas came back too) and I guess would also explain Namine? Unfortunately I don't remember when Xemnas said this, I think it was near the end of 3 or some time in re:mind, I'll have to look.
Also with Roxas and Namine, Ienzo mentions in KH3 secret report 9 that he retrieved data of both their data version's memories to reconstruct their hearts as well:
" Within Sora's heart are three compartmentalized "boxes," each containing the heart of another. One box holds Roxas. Another holds a second heart that has been with Sora nearly as long. The third has held its heart for much longer. These hearts have melded with Sora's and no longer have voices of their own. Any attempt to mechanically extract them could prove as dire for Sora as what caused him to become a Heartless in the first place.
First, a vessel for each heart must be readied. Then, a spark of some sort is required to induce its waking. Obviously, the ideal solution is to restore each heart to its own body, but (whatever the case for the two unknown individuals) Roxas possesses no such thing. The same is true for Naminé, who we believe resides in Kairi's heart. Still, if alternate bodies can be secured for them, all their hearts require to be awakened is that "spark"—people they cared for and who cared for them, who can show them the way home.
Complete and perfect digitalization of the heart is impossible. We can only hope to partially reconstruct it. Thus, I see no way forward but to extract the hearts we so desperately need directly from within Sora. Fortunately, the data stored in Twilight Town contains a near-perfect record of the memories of those who lived there—and for Roxas and Naminé especially, this is crucial. "