The Maryland Supreme Court affirmed Montgomery County’s ability to regulate firearms but narrowed how it can do so and left a sweeping ban open to a challenge.