Sherlock was fulfilling his last (and first) vow to John and Mary. John and Mary would never be safe while the archive existed and Sherlock protected them. Normally, yes, I'd say this was an out of character, idiotic move, but apparently Sherlock honors his vows.