Virginia Public Safety Secretary H. Selwyn Smith will leave Gov. John N. Dalton's cabinet July 1 to return to Prince William County as a state judge.

Smith, a former Democratic legislator, was elected by the state legislature to a newly created Circuit Court judgeship in the county. He will serve an eight-year term in the $47,000-a-year position.

Smith's election came in the final hours of the 1980 legislative session, and after considerably controversy in Northern Virginia over allegations of a political deal between Smith and Del. Floyd Bagley, a Prince William County Democrat.

According to reports in a Manassas newspaper, confirmed by sources in the legislature, Bagley, a long-time political foe of Smith's agreed to back Smith for the post. In return, the sources said, Smith agreed that he would appoint Bagley to a District Court judgeship after Bagley's House term expires in 1982.

Both Bagley and Smith have rejected those reports as untrue.

A member of the Prince William County Bar Association said this week that association members are still smarting at what they perceive as a slap at their role in the judgeship selection process.

"We aren't happy about it because the whole thing was just taken away from the local bar," said Manassas attorney Leo J. Scolforo. "[Bagley and Smith] made themselves candidates before the bar, and then subverted the whole process."

Earlier this year, the county bar association endorsed Judge Herman Whisenant of the Juvenile and Domestic Relations District Court for the new position, and Manassas attorney Joseph Gallagher for another circuit. judgeship to be filled when Judge Arthur Sinclair retires Aug. 1.

In other action Saturday, the legislature named Gallagher to a six-year term on the juvenile court, beginning Aug. 1. That position was created a week earlier, when Whisenant was elected to succeed Sinclair.

Smith, who served in the state Senate from 1972 to 1976, has held the state's top public safety post since he was named to the position by Governor Dalton, a Republican. Smith was an associate judge on Prince William County's trial justice court from 1950 to 1960 and was the county commonwealth's attorney from 1960 to 1968.