NEW YORK, JAN. 19 -- Joyce Brown, a former secretary who became a test case for the city's new policy of forcibly hospitalizing the mentally ill homeless, was released today after a state judge ruled that she could not be given medication against her will.

Brown, the first person committed to Bellevue Hospital under the city policy, was confined for 12 weeks. She celebrated her freedom with a news conference at the offices of her New York Civil Liberties Union attorneys, who gave her an ice cream cake decorated with a rainbow and inscribed "Welcome Home Joyce."

The Traveler's Hotel, a nonprofit residence for women on Manhattan's West Side, has offered Brown a room. She told reporters that she intends to find a secretarial job and will see a psychiatrist weekly.

Brown blasted Mayor Edward I. Koch's program of hospitalizing homeless people deemed by city officials to be a danger to themselves or others. Brown was hospitalized after Koch took a special interest in her life near a hot air vent on East 65th Street.

"I was incarcerated against my will . . . a political prisoner," she said. "The only thing wrong with me was that I was homeless, not insane.

"You just can't go around picking everyone up and automatically label them schizophrenic," Brown said. "I'm angry at Mayor Koch, the city and Bellevue. They held me down and injected me . . . . They took my blood against my will.

"I need a place to live; I don't need an institution," she said.

Brown said she learned two lessons from her 86-day incarceration. "People are treated differently just because of your economic status, what you look like and where you live," she said. Moreover, "It is you taxpayers who are paying for the $600-per-night hospital bill for people who are going nowhere and doing nothing."

City Councilman Abraham Gerges of Queens, saying that the city spent more than $42,000 for Brown's stay at Bellevue, said at the news conference, "I think that the mayor's ego got in the way of what was right."

A state judge had ruled last November that Brown was not dangerous, but the city prevailed on appeal.

Since New York began implementing its policy last October, more than 200 homeless people have been given psychiatric evaluations and 70 of them have been admitted to Bellevue. Of the 70, only eight have been discharged; the rest are confined at Bellevue or Creedmore, a psychiatric hospital in Queens.