At the moment Sora released his heart in Kingdom Hearts, Roxas was in the process of forming into the person we come to know him as.
During the time Sora spent in Castle Oblivion, Roxas was already aligned with the Organization. If you want a fuller picture of his whereabouts and experiences during this period, picking up Kingdom Hearts 358/2 Days for the DS is the best way to see his side of the story.