A major controversy is developing over the wife of an American diplomat who took part in an anti-government demonstration yesterday to protest the demolition of three black shantytowns near Cape Town.

The influential pro-government paper. Die Beeld, has already called for the immediate withdrawal of commercial affairs officer Tom E. Williams and his wife Judy, who are both white, and demanded that the U.S. embassy apologize for Mrs. William's conduct.

"It is improper for diplomats and their wives to get involved in internal tensions of the host nation," the paper editorialized.

Reflecting South Africa's growing hostility toward the U.S., Die Beeld commented: "The U.S. mission in South Africa might view the situation from another perspective: that Mrs. Williams' actions accord with the new approach of the Carter administration, which purposefully seeks to meddle in South African domestic affairs.

"The Cape Town incident contains within it the germ of bad faith. If American wants that, it will rest on her conscience because no proud, honorable nation can tolerate such effrontery."

Under banner headlines across the front page, a second newspaper - The Citizens - described the incident as "unprecedented in South African protocol history" and "an extraordinary breach of propriety."

A death threat was received by the U.S. consulate in Cape Town last night, although officials denied it was connected with the incident. Consular officials said police protection had been requested, as is routine when threats are received.

The controversy began when Mrs. Williams was present at the Modderdam site as about a hundred whites tried to form a human barricade to prevent government bulldozers from tearing down the corrugated tin and wood shanties. In all, about 3,500 shacks at Modderdam, Unibell and Werkgenot camps are scheduled to be destroyed under an order by the local Bantu (black) Affairs Administration, leaving about 26,000 blacks homeless in the middle of the Cape's rainy winter.

According to three reporters at the scene, Mrs. Williams volunteered the fact that she was the wife of a U.S. official and that she thought more whites should have joined the protest. A fourth reporter said Mrs. Williams said she was a member of the Women for Peace movement, which has a handful of representatives at the protest. And she was quoted in Die Beeld as saying: I think the demolition of the huts is terrible. I am surprised so few whites are interested in seeing what is going on."

But today a statement from the Cape Town U.S. Information Service said that Mrs. Williams went to the Modderdam site in a personal capacity "to offer assistance to a family of her acquaintance in connection with the family's move."

One of the white leaders of the protest the Rev. David Russell, an Anglican priest, said clergymen, social workers and members of the moderate Progressive-Reform Party had gone to the site to show sympathy with the squatters.

Cape Town police used tear gas and dogs to disperse a crowd of white protestors and black aquatters yesterday. Today Russell an two social workers were arrested for continuing the demonstration. Officials said they would be charged with trespassing on government property.

The squatters - estimated to number up to 300,000 in the Cape Town area - have always been a sensitive issue because they underline the problems of apartheid, South Africa's policy of separate development for separate races.The proliferation of shantytowns reflects the contradiction between demand for black labor on one hand and the shortage of housing and legal restrictions barring blacks from living in white suburbs on the other.

The situation developed after black and "colored" (mixed-race) contract workers, coming in from remote tribal reserves as transient labor for 11 months of the year, started bringing along families at a time when the government put a freeze on nonwhite housing. This is turn led to the sudden increase in shantytowns. Although the migrant workers have a right to live in the area, most of their families do not hold the government permits required for blacks to move into a white area.

Earlier this year the government announced that the squatters' camps were becoming a health hazzard and would have to be demolished, although there was no indication of where the families would be moved . Not all squatters will be affected - just the 26,000 who have settled since 1974.

When shanty residents refused to take down their homes voluntarily, government buildozers moved in Monday.