Echoing sentiments heard these days in the Norfolk bars frequented by sailors, Defense Secretary Caspar W. Weinberger said yesterday that four accused Navy spies, if convicted of espionage, "should be shot, though I suppose hanging is the preferred method."

As it happens, the spying suspects in question cannot be exe-cuted. The U.S. Constitution, which bars enactment of ex post facto laws (laws that have retroactive effect), protects them, since the laws they are accused of violating do not carry the death penalty. The maximum penalty for espionage now is life in prison, with eligibility for parole in 10 years.

To enact an espionage law that would provide for the death penalty for those convicted of violating it in the future would require lawmakers to confront a situation that has existed since 1972, when the Supreme Court struck down several federal death penalty statutes as unconstitutional.

"We want to restore it the death penalty for espionage , and it was our lead punch in the death penalty legislation we sent to the Hill last year," said Stephen S. Trott, the assistant attorney general in charge of the Justice Department's Criminal Division. "The Senate passes it, and then it goes to its grave in the House."

Recent charges that a spy ring, allegedly headed by retired chief warrant officer John Anthony Walker Jr., funneled classified documents to the Soviets for as long as 20 years have revived calls by the Reagan administration to bring back the death penalty for espionage. The crime is seen as both odious on its face and damaging to national security.

Weinberger said yesterday the Pentagon is studying how it can restore a peacetime death penalty to military law, and joined others in calling on Congress to add the death penalty to the espionage provisions of federal law governing civilians.

The last American spies to be executed were Julius and Ethel Rosenberg, according to the Justice Department's internal security section. The Rosenbergs, whose guilt remains a subject of debate, were electrocuted June 19, 1953, at Sing Sing prison in Ossining, N.Y., after they were convicted of passing atomic secrets to the Soviets.

Despite the visceral reaction many have to the idea of an American spying for the Soviets or other foreign nations, efforts to make espionage a capital offense automatically trigger the traditional debate for and against the death penalty in general.

"All of Western Europe has no death penalty," Henry Schwarzschild, director of the American Civil Liberties Union's Death Penalty Project, said yesterday. "Even in Israel there is no death penalty for espionage."

The Soviet Union and some Eastern European nations also have death penalty statutes that include espionage.

Proponents such as Trott argue that capital punishment is the best way to deter the modern breed of spy who is motivated by greed rather than political ideology. But Schwarzschild said capital punishment is not a deterrent to crime and would not prevent spies from selling secrets for money.

Schwarzschild and others also found irony in the call for the death penalty for espionage coming just after the United States traded four accused or convicted spies for 25 persons being held in East German and Polish jails.

"If you kill the spies, you won't have them as bargaining chips," Schwarzschild said.

The Supreme Court knocked down a series of capital punishment provisions in 1972, including the one for espionage, on the grounds that there was no constitutional procedure for implementing the sentence. Since the court decision, many states have enacted death penalty legislation that conforms to the court's guidelines.

Last year, the Senate approved a Reagan administration package that included provisions for implementing the death penalty for espionage and several other federal crimes, including treason, kidnaping and presidential assassination. It died in the House Judiciary Committee, where many key lawmakers are opposed to any expansion of the application of the death penalty.

"Maybe this incident the Walker case will give some impetus to the administration's push for it," said a congressional staff member familiar with the Senate-House deadlock.

Espionage or allegations of it are as old as the siege of Jericho, one death penalty opponent argued yesterday, and convicted spies and traitors don't always suffer the same fate.

Benedict Arnold, for example, the Revolutionary War general who deserted to the British after engaging in espionage and whose name became synonymous with treason, was allowed to go to England after the war, where he died in 1801.

Mata Hari, perhaps the most famous spy of all, was tried by the French and executed by a firing squad for spying for the Germans during World War I.

Since the Rosenberg executions, convicted American spies have been sent to prison if caught spying for other countries. Americans caught spying for the United States in foreign countries are generally sent home, which is what the United States does with suspected or blatant foreign espionage agents.

No matter what side of the street they are working, American spies get treated better than Nathan Hale. The 21-year-old Revolutionary War captain was hanged by the British in 1776 after he was caught spying, but went down in history when he exclaimed from the gallows, "I only regret that I have but one life to lose for my country."