Art museums do bag checks to protect the collections. Backpacks are sometimes carelessly slung around, which can strike sculptures or paintings, and things like drinks, knives, etc. have to be kept away from the art.
Portrait Gallery/American Art has one of the better policies; they encourage locker use, but otherwise it's fine as long as it goes on your front rather than back.