The Supreme Court agreed yesterday to decide whether a state violates the First Amendment by forbidding a newspaper to publish the name of a juvenile accused of a crime.

The issue arose in West Virginia when the morning and afternoon dailies in Charleston identified a youth alleged to have fatally shot a classmate in a hallway at a junior high school in St. Albans, W. Va.

A grand jury in Kanawha County indicted the papers and five executives and reporters for violating a 1941 state law making it a criminal offense for "any newspaper" to publish the name of an accused juvenile without a written order of the juvenile court. The law is silent on whether broadcasters can name an accused juvenile.

The slaying occurred Feb. 9 in the presence of seven witnesses. The victim was Arthur Smith, 14. The alleged assailant. Stuart Perrock, 14, was taken into custody three hours later. Police had found a message in the snow saying, "Tell Smith I'm sorry."

Because of the 1941 law, the afternoon Daily Mail didn't name Perrock in its report the same day. But then three radio stations and the morning Daily Gazette did identify him, and the Gazette also ran a photo of him. With that, the Daily Mail, on Feb. 10, also named him.

In a Gazette editorial the morning after the killing, editor Don Marsh said the decision "to break the law" was troubling and "maybe . . . simply wrong."

But, Marsh wrote, "everyone in the St. Albans area knows his [Perrock's] name and what he is charged with doing. I think it is a legalistic fiction for us to limit ourselves to 'a 14-year-old youth' or 'the juvenile suspect' . . . I think a very strong case can be made that the existing restrictions . . . are unwise and possibly illegal.

"If it comes to it," Marsh concluded, "the Gazette is willing to do whatever is necessary to have that belief tested as fully as court allow."

The test came quickly with the indictments, which both newspapers - owned by separate companies - appealed to the state supreme court.

Last June that court ruled the law unconstitutional. In doing so, it said it acted "in accord with crystal-clear principles of federal law concerning freedom of the press."

Moreover, the court cited "the preeminent rule" on prior restraint of publication expressed by Chief Justice Warren E. Burger in 1976 opinion: "Any prior restraint on expression comes to (the Supreme Court) with a 'heavy presumption' against its constitutional validity."

In a successful petition for review of the West Virginia decision, Kanawha prosecutor Cletus B. Hanley said that the effect of the law on freedom of the press "is relatively slight in light of the interest that that statute seeks to protect, i.e., a child's anonymity."

Hanley warned of the possibility that the press would publish the names not only of juveniles accused of violent crimes but also of those charged with such things as being "a habitual absentee from school."

The court took other actions: PRISONERS' RIGHTS

The court declined petitions by Maryland and South Carolina to review a ruling that a federal judge has a duty to assist a prisoner whose civil rights appear to have been violated, who doesn't have a lawyer and who is unable to represent himself effectively.

A judge who provides such aid neither violates his judicial neutrality nor denies due process of law to actual or potential defendants, the 4th U.S. Circuit Court of Appeals held in a 2-to-1 in May. The dissenter said that the duty to help amounted to a judicial assumption of a lawyer's role.

Because of the ruling, "what was formerly a right without the means for vindication may now become a reality for many prisoners," said Alvin Bronstein, executive director of the National Prison Project of the American Civil Liberties Union.

Bronstein told a reporter that in letting stand the 4th Circuit decision, which mainly involved advice to prisoners on how to proceed and how to determine who to name as defendants, the Supreme Court acted consistent "with prior rulings that prisoners have a fundamental right of access to the courts."

The South Carolina case involved prisoner Walter Gordon, who sued state officials after four other inmates robbed him, beat him brutally and homosexually raped him. Two guards watched but did nothing, he alleged.

The Maryland case involved Wayne S. Young, who sued because his watch was stolen from his cell while guards were searching it in his absence. CLEAR-CUTTING

The court let stand a decision that allows a clear-cutting in four national forests in Texas that was protested by an environmental group.