If Soji is a foreign leader then what she did is like threaten to destroy all organics with a super weapon.
No, what she did was summon a possible ally to defend herself and her people from a credible threat of genocide. And she had every reason to believe that the Federation would allow her people to be genocided, given the UFP's treatment of synthetics and of the Romulans.
We've seen how the federation deals with threats like with the mutagenic one in Chain of Command.
They neutralized the threat and then did not do anything to harm any Cardassians after that point, nor did they make any attempt to "rehabilitate" any Cardassians.
That precedent applies to PIC insofar as Picard already persuaded Soji to take a leap of faith in him and in the Federation by terminating the summons. Her leap of faith was rewarded when the Federation showed that it had grown past its passive allowance of mass death when the fleet showed up to deter the Tal Shiar. So the Federation is no longer in any danger.
She knew Riker and their daughter and others who had been nothing but kind to her and still had to convince herself not to destroy them.
She knew four things: 1) that a Tal Shiar fleet was bearing down on her and her people; 2) that the Federation had banned synthetic lifeforms like herself; 3) that the Federation had a history of standing by and allowing massive numbers of innocent people to die (Romulus); and 4) that the Admonition-Makers might protect her and her people.
Picard also knows something you are overlooking: That in spite of their advanced intelligence, in some ways the Coppelian Androids are akin to children in terms of the maturity of their cognition and understanding of how to relate to others. Picard realized that, like children, you have to give them the chance to make mistakes without condemning them -- and you have to show them love in order to build trust.
She should definitely be in a rehabilitation facility or something.
1) The Federation has absolutely no right whatsoever to imprison a foreign leader.
2) Trying to control her would just prove that you cannot be trusted not to oppress her and her people. It would merely re-create the marginalization dynamic.
ETA:
You want "rehabilitation?" Soji and Picard entering into a consensual familial relationship, assuming the roles of ersatz grandfather and granddaughter, is her rehabilitation. And Picard's rehabilitation. And the Federation's rehabilitation, too.