The Supreme Court ruled 5 to 4 yesterday that a judge erred when he refused to enforce Internal Revenue Service summonses for bank records on the ground that the IRS special agent who issued them "was conducting his investigation solely for the purpose of unearthing evidence of criminal conduct" by a bank customer.

The court cannot draw the line between permissible civil and impermissible criminal purposes "on the basis of the agent's personal intent," Justice Harry A. Blackmun wrote in the opinion for the court.

"To do so would unnecessarily frustrate the enforcement of the tax laws by restricting the use of the summons according to motivation of a single agent without regard to the enforcement policy of the (Internal Revenue) Service as an institituion," Blackmun said.

"Furthermore, the inquiry into the criminal enforcement objectives of the agent would delay summons enforcement proceedings while parties clash over, and judges grapple with, the thought processes of each investigator," he said. "This obviously is undesirable and rewarding. As a result, the question whether an investigation has solely criminal purposes must be answered only by an examination of the institutional posture of the IRS."

But the dissenters said that the burden of establishing the institutional good faith of the entire IRS is even less "undesirable and unrewarding" and will prove "wholly unworkable."

The elusiveness of such good faith, as described by the court, "can produce little but endless discovery proceedings and ulitimate frustration of the fair administration of the Internal Revenue Code," said Justice Potter Stewart, joined by Chief Justice Warren E. Burger And Justices William H. Rehauist and John Paul Stevens.

The case involved Special IRS Agent John F. Olivero; John Gattuso, a man Olivero decided to investigate on the basis of information he got from the FBI, and the LaSalle National Bank of Chicago,trustee of property from which Gattuso derived rental income reported in his tax returns.

To help determine the accuracy of the returns, Olivero in May 1975 issued summonses requiring the bank to produce papers relating to the trusteeship. A bank officer apeared at the specified time and place but declined to supply the materials. The government then asked U.S. District Judge Frank J. McGarr to enforce the summonses.

Citing a 1971 Supreme Court decision, McGarr refused. He said that the evidence showed that Olivero had used the summonses solely for criminal investigative purposes and that this demonstrated bad faith. The 7th U.S. Circuit Court of Appeals affirmed.

The Supreme Court reversed and sent the case back for further hearings. The dissenters would have reversed "with instructions to order enforcement . . . "

The 1974 decision allows the IRS to issue summonses to a third-party when it does so "in aid of an investigation" and "in good faith and prior to a recommendation for criminal prosecution." Yesterday's ruling was that the summonses to the bank complied with the decision and with the intent of Congress.