This page of the guide to NieR Automata explains why it's impossible to open the locked chests. You will also learn what requirements you need to meet to open the found locked chests, and how to find other loot chests more easily.
The description below contains a small spoiler about the structure of the game's campaign and the availability of a second playable character. We didn't include any major plot spoilers, though.
Chests that require hacking
You can come across the locked chests since the moment you reach the ruined city in the second chapter of the game. When you try to open such a chest, you will receive a message I can't access this right now.
Unfortunately, when playing the game in Route A (i.e. playing as 2B) you won't be able to open the chests because the heroine does not have the appropriate skills.
You can only start opening the chests after advancing to Route B. 9S has the hacking ability, which will be used e.g. to open the chests. Just like with other hacks, you need to stand close to the object you want to hack and hold the triangle (the button that was previously used for heavy attacks).
You will have to complete a hacking mini-game, and it should be its simplest type. You can also try again if you fail.
We've described hacking in more detail on a separate page of this guide, where you can find all the information about this mechanic.
The locked chests often contain very valuable loot. Try to open each new found chest, because this way you can obtain e.g. a unique melee weapon or some rare crafting ingredient.
Finding chests more easily
Further down Route B you can make finding chests easier by purchasing the Item Scan chip. It marks the chests and other loot on the minimap but this will only work if you have a HUD chip installed that allows you to display the minimap (it is enabled by default from the beginning of the game).
After you advance to Chapter 6 of the campaign, visit the Machine Village and talk to the Tool Shop Machine merchant from picture 1. The merchant will offer the Item Scan chip for 5000G. You need to buy and install it - it requires 6 free slots.
From the moment you install Item Scan, check the minimap frequently as you travel around the game world. Icons similar to those in the image above symbolize loot chests that you can examine. These can be ordinary chests or locked ones that require hacking.
Blue-and-white dots are also visible on the map. They inform about the "glowing" loot that you can pick up from the ground. It's obviously worth collecting as many treasures as possible from the explored location.