A federal judge on Wednesday told Imelda Marcos she was free to return to her Hawaiian exile home after millionairess Doris Duke put up $5 million in bail for the former Philippines first lady.

Duke, a tobacco heiress and once one of the world's richest women, said through her lawyer she was putting up the bail because "I am happy to aid Mrs. Marcos and the United States courts."Final details on the bail agreement were to be completed late Wednesday, but U.S. District Judge John Keenan said Mrs. Marcos was free to return to Hawaii until her next appearance on fraud and racketeering charges.

Mrs. Marcos, 59, pleaded not guilty on Monday to charges that she and her husband, ousted Philippine President Ferdinand Marcos, looted the Philippines of $103 million and used that money to secretly buy four Manhattan commercial buildings. She flew to New York from Honolulu in Duke's private plane.

Duke is the 75-year-old daughter of James Duke who was president of the American Tobacco Co. and underwriter of Duke University. He died in 1925 and left his estate to her at which time she was known as the world's richest woman. Her estimated wealth at the moment is $125 million and she is believed to have a checking account of $80 million.

Donald Robertson, a lawyer for Duke, said the heiress would sign the bail papers late Wednesday. He said she was delighted to aid her old friend and would turn over municipal bonds to secure the bail. The amount to be turned over would be slightly in excess of $5 million to account for market flucuations, the court was told.

Robertson, outside the court, told reporters, "People in some quarters regard the indictment as a double cross. First they invited the Marcoses to come to the United States and then they indict them. This is not fair play." He said that Duke feels that President Reagan regrets the indictment.

Keenan told the lawyers that his wife had gone to college with Corazon Aquino, who became president of the Philippines after Marcos was driven out of the country in 1986. But he said he has never met her and his wife has only seen Aquino once in the past 35 years.

While in New York, Imelda Marcos has been staying in an $1,800-a-day suite at the Waldorf Astoria hotel, which her spokesmen say is being paid for by friends.

In an interview with Cindy Adams of the New York Post, she said that she and her husband were flabbergasted by the high amount of bail. "It's like the government told us, `Commit suicide or we will kill you. It was a drop dead deal,' " she told the reporter, who is an old friend.