The Supreme Court ruled yesterday that states rich in natural resources cannot make out-of-state consumers pay higher prices for them.

In a ruling non-energy-producing states hope will prevent energy producers from behaving like OPEC nations, the justices said it was unconstitutional for Louisiana to impose a special tax on offshore natural gas passing through the state.

The tax cost consumers in other states between $200 million and $300 million a year. Eight states, led by Maryland Attorney General Stephen H. Sachs, challenged the tax, saying it was flagrant violation of the Constitution, the equivalent of a duty charged by a foreign nation.

The justices agreed, 7 to 1. Louisiana unconstitutionally obstructed free commerce between the states with its discriminatory tax, Justice Byron R. White wrote for the court. And it unconstitutionally "usurped" federal authority to oversee natural gas costs.

The case was a product of energy crisis of the past decade. Reacting to the dependence on foreign resources, energy companies dramatically stepped up offshore exploration and drilling. States containing or bordering the newly plumbed resources sought to cash in on the boom. Soon the non-producing states began complaining that now they were being "gouged" not only by the Arabs, but by their sister states in the Union. They referred to these states as "blue-eyed Arabs."

Yesterday's ruling does not necessarily resolve other cases growing out of the controversy, such as a challenge now before the justices to a coal severance tax imposed by Montana. It also does not rule out all revenue measures by states wanting to capitalize on resources. It does appear to force them to impose such measures equally on in-state and out-of-state consumers.

Louisiana enacted a tax of 7 cents per thousand cubic feet on natural gas imported into the state from offshore wells on federal property. It is called a "first use" tax because it is paid by the companies that first handle the gas on Louisiana territory; in most cases, these are the pipeline companies which pump it to the rest of the country. The tax is imposed on all gas, including that meant for use within Louisiana. But Louisiana users get various tax credits and exemptions which offset the "first use" tax.

Louisiana said the distinction was, in part, designed to compensate Louisiana for the environmental and demographic impact of the natural gas drilling. That left approximately 30 other states to bear what Sachs estimated to be a $300 million burden. Under Louisiana laws, the tax has to be borne by the ultimate consumer, meaning out-of-state homeowners, industries and governments.

It was that discrimination between in-state and out-of-state consumers that violates the Constitution's commerce clause, White ruled.

"Gas crossing a state line at any stages of its movement to the ultimate consumer is in interstate commerce during the entire journey," White wrote. The commerce clause was designed to ensure that nothing interfered with or obstructed the free flow of business between states, he said.

Louisiana breached a "fundamental principle" of the clause with its tax, he wrote for the court, because it benefited local interests at the expense of the rest of the country.

"This antidiscrimination principle 'follows inexorably from the basic purpose of the clause' to prohibit the multiplication of preferential trade areas destructive of the free commerce anticipated by the Constitution," he said.

On the second issue, White said Louisiana also violated the clause in the Constitution that makes federal law superior to state law. Under the Natural Gas Act, the Federal Energy Regulatory Commission, not the states, is responsible for pipeline and producer pricing polices, he said.

"The state may not trespass on the authority of the federal agency," he said.

Justice William H. Rehnquist dissented, saying the court should not have ruled on the case at all. Justice Lewis F. Powell Jr., who owns energy stocks, did not participate.

Sachs said yesterday that Maryland consumers have already paid $8 million because of the tax. He said the money, held in escrow pending the Supreme Court decision, should now be refunded.

"It was not a tough decision for the court," Sachs said, noting that there were no dissents on the primary constitutional questions. "It was a flagrant case. The energy-rich states are obviously lusting to take advantage of their position. This puts them on notice that they cannot forget" that they are part of the Union.

Illinois, Indiana, Massachusetts, Michigan, New York, Rhode Island and Wisconsin joined Maryland in the suit.

Washington Gas Light Co., the metropolitan areas's sole gas distributor, expects a refund of about $4.5 million, according to spokesman Paul Young. Passed on to gas users, he said, that would translate into an average refund of $6.50 for residential heating customers.

Currently the company provides gas to about 545,000 customers, most of them private residences. In Washington, Young estimated, Louisiana's tax added just over 2 cents to the price of gas, now standing at about $4.80 cents per thousand cubic feet.

Washington area consumers could expect their refunds as reductions on their gas bills, Young said. "This is the traditional way that is used for refunds flowing back to customers," Young said. Church School Taxes

In another major ruling yesterday the court said that federal law exempts parochial and church-related schools from unemployment taxation.

Private businesses pay the tax to cover unemployment compensation for employes laid off or fired. In 1976, the federal government extended the tax to church schools and ordered the states to collect it.

The religious groups charged that this breached the wall separating church and state, and they made the case a major legal issue for organized religion. A South Dakota church, St. Martin Evangelical Lutheran, brought suit to prevent imposition of the tax on a secondary school it operates.

Their victory yesterday was largely a financial triumph, however, since the court did not rule on the constitutional issue. Instead, it said Congress meant to exclude church schools in its 1976 amendments to the Federal Unemployment Tax Act.

Justice Harry A. Blackmun delivered the court's unanimous opinion. Justice John Paul Stevens filed a concurring opinion. Murder Case Review

In other action yesterday, the court agreed to review the case of former Green Beret captain Jeffrey R. MacDonald convicted in 1979 of murdering his wife and two children at Fort Bragg, N.C.

The Fourth U.S. Circut Court of Appeals overturned the conviction last year because of the delay in bringing MacDonald to trial for the 1970 slayings.

The MacDonald case is one of the most protracted and controversial murder proceedings on recent record. The Army first charged him with the crimes and then dropped charges. The government reopened the case under pressure from MacDonald's father-in-law and, after several years of investigation, charged him again in 1975.

MacDonald, who served a portion of his life prison sentence before the conviction was reversed, is now practicing medicine in California. He continues to maintain that he and his family were attacked by what appeared to be a Manson-style cult that invaded his home. A private investigator, employed by friends of MacDonald, has produced a woman who claims to have participated in the attack.

Had the court declined to hear the case, MacDonald would have remained a free man. The court can now reinstate his conviction or order further proceedings or uphold the lower court decision. K-9 Drug Searches

The justices refused to review a decision allowing warrantless dragnet searches of students in junior and senior high schools by officials and German shepherds hunting drugs.

The search took place at Highland Junior and Senior High School in Highland, Ind., in 1979. School officials ordered all students to remain in their seats while 14 dogs, dog handlers and others marched up and down the rows of desk.

When the dogs indicated the presence of drugs, students were searched or forced to empty their pockets. Officials found drugs or other contraband on 17 students out of 50 singled by the dogs.

One 13-year-old girl was forced to undress in a school office for a search after a dog indicated the presence of drugs on her. It turned out that the dog was reacting to the scent of the girl's own pet, who was in heat.

The girl filed suit. Lower courts ruled the strip-search an invasion of privacy but termed the rest of the dragnet constitutionally valid.

Justice William J. Brennan filed a vigorous objection yesterday to the court's refusal to hear the case. "I cannot agree," he said, "that the Fourth Amendment [protecting against invasions of privacy] authorizes local school and police officials to detain every junior and senior high school student present in a town's public schools and then . . . to conduct a warrantless, student-by-student dragnet inspection. . . ."