It is perhaps typical of the ironies and anomalies that permeate Iran's Islamic revolution that the same man who staged Sunday's macabre display of American corpses here has been the only leading Moslem cleric to call for the release of the U.S. hostages.

Ayatollah Sadegh Khalkhali combines many of the characteristics that make the Iranian revolution so baffling and unpredictable for most Westerners and even for many Iranians.

Khalkhali, a basically good natured fellow, can send a man to the firing squad without batting an eyelash. He is generally considered to be one of Iran's most fanatical Moslem clergymen and a close confidant of Ayatollah Ruhollah Khomeini, but he has backed the secular government of President Abol Hassan Bani-Sadr against its clerical rivals.

Khalkhali's behavior alternates between buffoonery and barbarism. He can appear to be sinister or simple, ignorant or cunning, humane or sadistic. The mention of his name can inspire ridicule or fear.

Some Iranians have nicknamed him "Ayatollah Attila." It is a sobriquet that probably would not displease him. He seems to enjoy his notoriety.

Khalkhali's performance as he displayed the fire-blackened remains of eight American servicemen at the U.S. Embassy Sunday contained many of the contradictions that make up his personality.

He began the news conference by saying, "I would like to offer my condolences to the families of the victims in the United States who have become cought by the treacherous and shameless thoughts of [President] Carter and the U.S. government. God knows how I became sad by seeing the [servicemen's] bodies and their pitful condition."

Minutes later he ordered Revolutionary Guards to cut open the plastic and cloth wrapping around the Americans' remains and displayed the contents to a group of Iranian and foreign reporters who had been previously screened by the embassy militants.

Yet at other times Khalkhali has displayed compassion for the American hostages that the servicemen had come to rescue. In December his statements startled reporters who visited him at his home in the Shiite Moslem holy city of Qom to ask his opinion about the hostages seized a month before.

"We should release them," the pudgy, bespectacled clergyman said. "They are our guests."

Since then Khalkhali has blown hot and cold on the issue, but his line generally has been that the hostages should not be harmed.

In his latest remarks on the subject, he said: "The Islamic Majlis [parliament] will decide their fate. Hope their files will be attended to after the Majlis begins. Those who have a small file should be freed, and those who have committed heavier crimes should be punished according to the law." He said he does not believe any of the hostages should be executed.

Coming from a man who has ordered the executions of over 300 Iranians in the past year in his capacity as a revolutionary court judge, that comment struck some observers here as a hopeful signal for the hostages.

When it comes to dispatching former Iranian officials under the shah or "counterrevolutionaries" to firing squads, Khalkhali has shown no qualms, earning a reputation as the revolution's "Judge Blood."

"Khalkhali can be extremely sentimental one minute, and off slaughtering people the next," one long-time resident of Tehran said.

As the chief judge of the Islamic revolutionary courts immediately after the February 1979 revolution, Khalkhali passed death sentences on former prime minister Amir Abbas Hoveyda and a number of the shah's top generals. The sentence were usually carried out after summary late night trials.

Recently Khalkhali responded to criticism that sentencing people to death at night was not in keeping with Islamic priniciples. "In Islam what is important is having peace in your work," he told a reporter. "And I work more peacefully at night."

Khalkhali said he had lost count of how many persons he had sent to firing squads. "But it's at least four times as many as any of the other revolutionary judges," he was quoted as boasting.

Khalkhali also has bragged of sending a hit team to assassinate deposed Shah Mohammad Reza Pahlavi after sentencing him to death in absentia and has claimed responsbility for the murder of the ex-monarch's nephew, Prince Shahriar, in Paris in December.

These and other unsubstantiated statements combined with his treatment of the American corpses in the embassy compound have made Khalkhali an embarrassment to a succession of civilian government officials.

But he has consistently enjoyed the support of Khomeini, who is said to value Khalkhali as one of his most trusted and loyal aides and a key member of his inner circle.

With a background similar to Khomeini's, Khalkhali was one of the Iranian revolutionary leader's earliest disciples. Born in 1927 to a poor, devoutly religious farming family in the northwestern region of Azerbaijan, Khalkhali received theological training in Tehran before attending the Feizieh school of Qom, which Khomeini helped found. Khalkhali became one of Khomeini's mullah proteges in 1952 and joined the Fedayan-e-Islam guerrilla group that began fighting the shah in the late 1940s.

Khalkhali went into hiding when several leaders of the group were executed in 1955. Later he played a part in the anti-shah demonstrations in 1963 that led to Khomeini's expulsion from Iran by the shah the following year. Khalkhali was arrested and jailed for his activities, but was later released and became one of the principal agitators for the revolution against the monarchy.

Last year Khalkhali ran for election to Iran's constitutional assembly, campaigning on his record as revolutionary judge. A crushing defeat in that election did not deter him from becoming a candidate for the presidency, an office he continued to campaign for even after Khomeini had banned all mullahs from the race.

Finally pulling out shortly before the election in January, Khalkhali threw his support to Bani-Sadr. He was quoted as declaring, "I'm the best man for the job, but I'm stepping down in favor of the second best man for the job."

Khalkhali's political fortunes improved with the parliamentary elections, and he was a first round shoo-in as one of the deputies from Qom.

Countrary to a comment this week by President Carter, Khalkhali is not now, and probably never has been, a member of the ruling Revolutionary Council, according to political sources here. But he continues to weld considerable influence as one of Khomeini's right-hand men.

He dismisses stories circulated by his critics that he was once committed to a mental institution, allegedly because of a penchant for strangling cats, as part of a plot started by the shah's agents to discredit him.