NEW YORK (AP) _ The garbage barge that returned to New York after an eight-week, 6,000-mile voyage of rejection has encountered a legal blockade.

A state Supreme Court judge today extended a temporary order barring the barge from docking in the city, allowing two days for city health and sanitation officials to inspect its well-traveled cargo.

Six states and three countries have shunned the refuse, making the barge a floating symbol of overflowing landfills and fodder for comedians and cartoonists. It anchored Saturday at 11 p.m. in Gravesend Bay, 700 yards south of the Verrazano-Narrows Bridge.

Queens officials had asked Justice Angelo Graci of the trial-level Supreme Court to prevent the barge from landing in the borough until its cargo is checked for toxic substances and until it is determined where the garbage will go and who will pay the bill.

After a hearing today, Graci allowed a two-day extension on his hearing on a preliminary injunction that would stop the barge from docking until it meets the city's conditions. City lawyer Doron Gopstein, who asked for the extension, said inspectors boarded the barge this morning.

''It's very risky stuff,'' Queens Borough President Claire Shulman said Sunday. ''We don't know what's in it. It's been sitting in the hot sun for weeks. It probably contains tropical insects and vermin.''

Mayor Edward I. Koch and other city officials have insisted that enclosed sanitation trucks be used to take the garbage from Long Island City, Queens, to Islip, N.Y., which has agreed to take the garbage.

Islip, which was running out of landfill space, had the garbage loaded onto the barge in Queens on March 22. But when a deal to use it for a methane-gas project in North Carolina fell through, the voyage down the coast and around the Gulf of Mexico began.

''Ours is not to question why,'' said David Soto, the mate of the barge's tugboat, Break of Dawn, on Sunday. ''We just go where they tell us. We won't mind when this is all through.''

Islip received permission last week from the state to take the garbage back, but that plan was thwarted by a suit Friday by the New York Public Interest Research Group that claimed the waste was ''potentially contaminated.'' The Queens injunction and the city's demands followed.

''If the garbage is described as safe by the Department of Health and if, simultaneous with the scow coming to a pier, there are also closed sanitation trucks to take it to Islip, we will allow it,'' Koch said Sunday.

''We are treating the garbage like Germany treated Lenin,'' when the Communist revolutionary returned to Russia, Koch said. ''He had to be in a sealed train as he went through Germany, Poland, until he got to Finland. This garbage has to get onto sealed trucks until it gets to Islip.''

Towboat owner Robert Guidry of Harvey, La., who arranged the towing contract, estimated the barge has 160 truckloads of garbage on it.

''It'll take about a week to offload that thing,'' he said.

The barge contains garbage from Islip, New York City and Nassau County. It has been rejected by North Carolina, Alabama, Mississippi, Louisiana, Texas, Florida, Mexico, Belize and the Bahamas.