The hopper only works to place items in the chest if the player shift-clicks onto the chest but if the player places the hopper using a block up and behind the chest the hopper visually doesn't connect and won't deposit items from the hoppers buffer.
This is not a bug, the hopper connected to whichever block face you place it against, and will deposit to that direction; So in this case it'll deposit to where the sandstone is if replaced with a chest.