The Supreme Court yesterday struck down vagrancy and loitering laws that give police broad powers to demand identification from people stopped on the street.

In a 7-to-2 decision, the court said that such vague laws give virtually unlimited discretion to the police to decide who walks the streets.

The ruling is an important victory for civil liberties advocates, who say that the police have been using such laws to harass unconventional people or blacks walking through white neighborhoods.

American Civil Liberties Union lawyers said that the ruling in Kolander, Chief of Police of San Diego, et al. vs. Lawson, would cause a reexamination of laws or police practices in half the states.

District of Columbia lawyers said the decision could alsoaffect a local case challenging the authority of the police to ask pedestrians to produce identification.

Law enforcement organizations such as the International Association of Chiefs of Police, had told the court that such police powers were crucial to prevent crime.

Wayne W. Schmidt, director of Americans for Effective Law Enforcement, said yesterday that he believes the ruling leaves room for states and cities to draw up new laws that might be acceptable to the court.

The decision was a personal victory for Edward Lawson, a black Californian detained and questioned by the police 15 times during a two-year period while walking or hitch-hiking in predominantly white areas of San Diego and Chula Vista.

On three of those occasions, Lawson was arrested under a California law requiring "credible and reliable" identification by those stopped. Lawson, who attributed part of his problem to his hair style--dreadlocks--challenged the law's constitutionality.

Justice Sandra D. O'Connor, writing for the court, said that the California law allows innocent people "to continue to walk the public streets 'only at the whim of any police officer' who happens to stop" them.

She said that the statute was too vague because it failed to inform suspects what they had to do to provide "credible and reliable" identification. It thus gives police unlimited discretion to make that determination. Such vagueness, she said, allows "arbitrary enforcement" against unpopular groups or individuals.

O'Connor said that vagueness must be even more carefully scrutinized when a law, such as California's, jeopardizes "freedom of movement" protected by the Constitution and the Fifth Amendment's prohibition against self-incrimination.

The latter is "implicated" because the statute punishes someone for failing to answer a question, O'Connor said.

The majority ruling, affirming a decision of the 9th Circuit Court of Appeals, did suggest that a more detailed and carefully defined law, containing "minimal guidelines" for demanding identification, might meet constitutional standards. But the court offered no specific suggestions for drawing up an acceptable law.

Justice William J. Brennan agreed with the decision, but said he would have issued a broader holding that the California law violated the Fourth Amendment's guarantee against unreasonable search and seizure.

Justices Byron R. White and William H. Rehnquist dissented. They said the law was "clear in many of its applications" and was struck down just because it was "somehow distasteful" to the court majority.

The decision, they said, "serves as an open-ended authority to oversee the states' legislative choices in the criminal-law area and in this case leaves the state in a quandary as to how to draft a statute that will pass constitutional muster."

In another major decision yesterday the justices ruled that school districts in Texas can deny free admission to children, even U.S. citizens, who move in just to get an education.

The case, Martinez vs. Bynum, was one in a series of recent controversies over the cost of educating residents of Mexico in the United States. Last year the court struck down a Texas law denying free education to illegal aliens.

The restriction at issue yesterday applied to a much smaller group: children born in the United States but living in Mexico. Many of those children come back to this country to live with friends or relatives to take advantage of the public schools.

In response, Texas passed a law requiring children living with persons other than a parent or an official guardian to show that their presence in a district is not for "the primary purpose of attending school there."

The case involved Roberto Morales, 8, who left his parents' home in Reynosa, Mexico, to return to his birthplace, McAllen, Tex., and live with his married sister. His purpose was to attend McAllen schools.

Texas officials, defending their law, said that it was actually less restrictive than the residency requirements imposed by many states and a legitimate means of controlling a potential drain on local treasuries.

Justice Lewis F. Powell Jr., writing for the 8-to-1 court yesterday, agreed. "The Constitution permits a state to restrict eligibility for tuition-free education to its bona fide residents," he said.

The Texas requirement is "more generous" than some standards for residency, he said, since it only requires a student to show some reason, such as health, for moving to a district.

In other action yesterday:

The court rejected a challenge to the free mailing privilege--the franking privilege--allowed members of Congress. Common Cause, the self-designated citizens lobby, contended that the franking system is an unconstitutional subsidy for incumbents that puts challengers at a disadvantage.

The justices affirmed without comment an appeals court decision that went against Common Cause in Common Cause vs. Bolger. Justices Brennan, Thurgood Marshall and John Paul Stevens dissented, saying they thought the court should conduct a full review of the case.

The court turned down an appeal from Joseph Margiotta, the Nassau County, N.Y., Republican leader convicted in 1981 in a mail fraud and extortion scheme.