President Fidel Castro sharply criticized U.S. mediation in southern Africa today, charging that the Reagan administration is an "ally" of South Africa and therefore unfit to serve as go-between with Angola.

Addressing 600 youths here from Namibia, the Cuban leader said that "not a single Cuban soldier will be withdrawn from Angola until concrete steps" are taken to carry out United Nations Resolution 435, which spells out a U.N.-supervised transition to independence for the South African-ruled territory. And if more soldiers were needed, he said, Cuba would send more.

Castro's remarks demonstrated his evident irritation at the capture last week of a South African commando team that he said was trying to sabotage U.S.-owned oil installations in Angola's Cabinda enclave.

The sharp tone also reflected official Cuban anger at the start-up 10 days ago of Radio Marti, a U.S. government broadcasting facility beaming news and commentary specifically at the Cuban people.

But despite the tone of his comments, Castro did not quite close the door to cooperation with the U.S.-led effort to mediate an agreement between South Africa and Angola.

Castro said last February that he was prepared to cooperate in the U.S.-led mediation effort, which would link independence for Namibia to withdrawal of about 20,000 of the Cuban troops that have been helping the Marxist government of Angola fight South African-backed guerrillas. About 10,000 Cuban soldiers remaining behind under the agreement would be concentrated in the Angolan capital, Luanda, and in other northern points, including the Cabinda oil fields, where Gulf Oil produces about 150,000 barrels a day, he added then.

Castro's statements today, with United Nations Secretary General Javier Perez de Cuellar looking on silently, appeared to indicate a hardened posture on the possibility of pulling out the Cuban troops.

"There will be no solution in southern Africa without Resolution 435 and without the independence of Namibia," he declared. "Through Angola have passed 200,000 Cubans and, if necessary, 200,000 more Cubans will pass through there."

The recent developments in Africa have combined with the beginnings of Radio Marti to dash an impression here during the last six months that there was a possibility of lessening tensions with the United States in President Reagan's second term, Cuban and other Latin American diplomats said.

Two days before today's address, for example, the official Communist Party newspaper Granma published an unusually long front-page editorial saying the "U.S.-South African axis" is composed of a pair of "freebooters" -- language of a tone the official Cuban media had avoided since the beginning of the year, these diplomats added.

Castro seized on the theme with his customary gusto as he spoke here today at the Hendrick Witbooi secondary school for Namibian youths affiliated with the Southwest Africa People's Organization (SWAPO), fighting for the independence of the South African-ruled territory that lies between South Africa and Angola.

Castro visited the installation on this island just off Cuba escorting Perez de Cuellar, who is on a four-day official visit to Cuba.

U.N. Security Council Resolution 435 underpins efforts by the Reagan administration to foster an agreement between South Africa and Angola, which has offered refuge to SWAPO forces fighting South African control over the territory.

The Reagan administration also has sought to link the agreement to withdrawal of Cuban troops from Angola.

After refusing the attempt at linkage over several years, the Angolan government announced last November that it would agree to a phased withdrawal of 20,000 Cuban soldiers from southern Angola over three years. In return, South Africa would pull out of Namibia, grant the territory independence and stop aid to the guerrillas of Jonas Savimbi's National Union for the Total Independence of Angola (UNITA).

In his comments here today, Castro, after recounting the South African commandos' capture in Cabinda, ridiculed South African and American statements on the subject and implied President Reagan was lying along with President P.W. Botha of South Africa.

"They never tell the truth -- neither Reagan nor Botha," he said. "Not even by accident. I am waiting for the day when they will make a mistake and, by accident, actually tell the truth."

Botha's government has maintained that the commandos were on a reconnaissance mission. The United States last week expressed concern over the operation.