Linwood Gray, the Southeast Washington man the government has accused of masterminding a multimillion-dollar herion ring, cursed and shouted at a magistrate yesterday, berated a federal marshal and tried to dismiss his own attorney before he was finally escorted bodily from a bond hearing.

Gray shouted at U.S. Magistrate Henry H. Kennedy Jr., who is black, "You claim you're a Kennedy; you're not a Kennedy; you look like a Martin Luther King... You can be Gov. Wallace or somebody but not a Kennedy."

Moments earlier in the hearing, federal marshal Walter Rich told Gray to keep quiet as Gray and a codefendent conferred at the defense table. Gary snapped, "We in session here. You should keep your hands off perple, that's what you should do."

Gray, who is 6 feet 1 and weighs about 210 pounds, entered the hearing wearing a light shirt, dark blue trousers, a gray leather jacket, and a grim look. He announced that he was representing himself, and when Kennedy disregarded that, Gray yelled to the bench: "I do have something to say and if you won't let me have my say, I'll leave."

Gray was arrested earlier this week and charged with heading a smuggling ring that allegedly imported at least 100 pounds of high-grade heroin, worth some $30 million on the streets. He is being held on $150,000 bond.

"Something made him mad," Gray's attorney, Kenneth M. Robinson, said of Gray in response to a reporter's question."I'm not going to argue with him -- his arms are bigger around than my legs."

Law enforcement sources have said privately that they suspect Gray might be building toward an insanity defense against the government's charges.

That defense has served Gray in the past. He spent six years at St. Elizabeths Hospital after he was charged with carring a dangerous weapon and bank robbery, and was found not guilty by reason of insanity.

In a court appearance in 1967, he beat up a probation officer in court and had to be removed by four court officers. He later boasted to a friend in a letter from St. Elizabeths that the attack, plus his feigned insanity, enabled him to beat the charges against him.

Gray was released unconditionally from St. Elizabeths in 1976, and government sources allege by that same year he had established an international smuggling operation that delivered a steady supply of heroin from Southeast Asia, through Amsterdam, to Washington.

Police began making arrests here in the case shortly after midnight Tuesay when federal and local agents arrested Gray in front of an apartment at 1101 Kennebec St., Oxon Hill.

Federal agents had followed two alleged heroin couriers from Amsterdam to Canada to Boston to National Airport for what was alleged to be rendezvous with Gray, sources said.

The supected couriers took a cab from the airport to the Kennebec Street address, where one of them had an apartment, and they telephoned Gray, according to law enforcement sources.

One of the alleged couriers, Smith D. Hammond, was sure they were being followed and was so nervous he yomited in the apartment, informed sources said, even though the other man, Ernest who was working covertly with the government, tried to reassure him he was not falling into a trap, the sources said.

When Gray arrived at the apartment, federal agents and local police swept in and arrested Gray, one of his alleged lieutenants, and Hammond. Others were arrested at their residences through the night.

During the arrest processing Tuesday, Gray stunned a number of law enforcement officers, who thought they were strangers to him. One by one, he revealed that he knew who each agent was, and recited from memory the license numbers of the cars they used while they observed him during the investigation, according to informed sources.

Gray's bond hearing yesterday was continued until Monday. Three other defendants, Barbara Ann Greer, Darlene Beverly Flemming and Joseph F. Wilson, posted bond and were released.

During a bond hearing for one of the the defendants, assistant U.S. Attorney Barry M. Leibowitz said that members of the alleged Gray ring had arranged for the murder last October of another suspected ring member, Ernest Minder, when it was feared he was going to talk to the government.

Afterward Gray's attorney, Robinson, said Gray could not possibly have had anything to do with the slaying. "Minder was a dear, close friend of Linwood's," Robinson said.

The bond hearings for Gray and nine other defendants charged with him in an alleged conspiracy to viplate federal narcotics laws, have been going on for the past four days, with Leibowitz and Robinson arguing vehemently over the amounts of bonds.

At one bond hearing yesterday afternoon, U.S. District Judge William B. Bryant asked Leibowitz, "Why are you so emotional about this?"

Leibowitz, who was shot and slightly wounded outside the court-house last month by a gunman still at large, started to explain, "The reason I get emotional, your honor, is...," when Bryant cut him off.

Leibowitz, who is under round-the-clock protection by U.S. marshals, beckoned his marshal into the courtroom and stalked out of court.

He returned a few minutes later and told a reporter, "The answer, had I been able to give it, is that I feel some obligation not to let a pound of heroin onto the streets." CAPTION: Picture, LINWOOD GRAY,... held on $150,000 bond