Unfortunately, no. In Star Wars: Knights of the Old Republic II, once Dhagon Ghent ends up in jail, there is no way to get him back out. The story simply locks him there, so you will have to continue without freeing him. Sorry to deliver the bad news, but that is how the situation plays out in the game.