The prosecutors say that testimony from the teenager, who twice ran away from a foster home before scheduled court appearances, is critical in the upcoming trial against a man who has a long criminal record and is also suspected of raping at least one other woman. But the teenager’s lawyer and victims’ advocates say that the detention would discourage others, especially those who have been sexually assaulted, from coming forward. They described the move as a setback in a state with some of the country’s strongest laws protecting victims.