A federal judge agreed today to transfer Michael L. Walker to an unspecified federal prison from a small county jail in northern Maryland where he has complained of cramped quarters and limited freedom while awaiting trial on espionage charges.

Judge Alexander Harvey II granted Walker's request but did not indicate when the prisoner will be removed from the Harford County Detention Center in Bel Air or where he will go.

Walker, 22, a Navy seaman, is scheduled for trial in federal court here after the trial starting Oct. 28 of his father, John Anthony Walker Jr. The elder Walker, who is retired from the Navy, is charged with masterminding a conspiracy with his son, his brother, Arthur, and an old Navy friend, Jerry Alfred Whitworth, to sell Navy secrets to the Soviet Union.

There are no federal prisons in Maryland. Federal prisoners awaiting trial ordinarily are kept in Baltimore City Jail or other nearby facilities. John Walker is being held in the Montgomery County Detention Center.

The nearest federal prison to Michael Walker's home in Virginia Beach is in Petersburg, Va., but defense attorneys would not comment today on whether he would be transferred to that facility.

In his request for a transfer, Michael Walker complained that he is restricted to his 6-by-8-foot cell in Bel Air 23 hours a day and is allowed out only to take showers. Since his trial "will not take place until the end of the year, this current incarceration is extremely difficult for him," Walker's attorneys wrote in a plea to Judge Harvey. "A transfer to a federal institution would be in the best interest of justice."