WASHINGTON—The Supreme Court appeared narrowly divided Tuesday over whether states can bar judicial candidates from soliciting campaign donations without violating the First Amendment.

Florida, like most states, elects some or all of its judges. While it allows judicial candidates to set up campaign committees that solicit and spend election funds, Florida prohibits them from “personally” soliciting contributions—a restriction the state concedes would be unconstitutional if applied to candidates for legislature or other political...