Not all the keys can be restored after a Flawless attack - if you obtained some from watching ads or buying for orbs, they won't be restored. Also, if you had to open the locks in two parts (you watched an ad to get more lock picks and it made the game reconnect for some reason and you continued opening the locks after finding the same dungeon in the Attack mode after reconnecting), the lock picks spent before the reconnection won't be restored.