federal judge ruled today that letters to and from Rep. Frederick W. Richmond (D-N.Y.) concerning convict Earl W. Randolph Jr. "must be delivered" to a grand jury investigating the four-term congressman.

Richmond's lawyers had attempted to quash a subpoena calling for production of the letters on grounds that they were personal and that turning them over to the federal grand jury would violate Richmond's Fifth Amendment privilege against self-incrimination.

Late today Richmond's attorneys moved to stay the order pending an appeal.

The grand jury in Brooklyn is investigating whether Richmond violated a federal statute that prohibits an individual from aiding a person he knows to be a fugitive.

In July, 1980, Randolph, 28, a longtime friend of Richmond, escaped from a Massachusetts prison. Six months later, under the name John McLoughlin and on the recommendation of Richmond, he got a low-paying Capitol Hill job in the document folding room of the House doorkeeper.

Randolph was subsequently arrested for male prostitution in New York City after he solicited an undercover policeman and suggested that they perform a sexual act in a car that turned out to be Richmond's. Randolph is now back in custody.

In his ruling today, Judge Jack Weinstein said that "while the congressman's letters may have been written for private reasons," they must be turned over to the grand jury because they were "clearly written in his capacity as a congressman on congressional stationery, using his congressional title and with the aid of the congressman's paid staff."

The correspondence in question includes references to Randolph and McLoughlin, according to statements at a preliminary court hearing Friday.

Richmond's lawyer, Samuel Dawson, told the judge, "There are correspondence materials that bear on both of those names."

It was also revealed that the letters were both to and from Richmond.

The correspondence, which was contained in a small envelope, came from files in Richmond's congressional office, according to Dawson.

Government lawyer Renna Raggi told Weinstein on Friday that, based on the investigation to date, several of the letters "were . . . written by members of his Richmond's congressional staff."

One key letter that Richmond has publicly said he wrote, but that has not yet turned up, was to Rep. John J. Moakley (D-Mass.). The letter was said to have recommended Randolph under the name McLoughlin for a Capitol Hill job. Moakley is head of the House Democratic patronage committee and the man who arranged for Randolph to get the job.

The House Committee on Standards of Official Conduct has announced a preliminary investigation into Richmond's activities; that inquiry is being carried out behind closed doors.