Has William gone to the basement before you try using the hammer? If so, I'm stumped too, you should have plenty of time before William returns.

It is possible, if you're a slow player, that William has time to return to the right gallery before you can use the hammer. All I can suggest is to repeat showing him the box & keep trying!