This is only partial and rather speculative answer, but it is a bit too long for comment.
A short historical overview of the Latvian State History Archive (LSHA) is found (in Latvian) on its webpage, which was linked in my original comment: http://www.latvijasarhivi.lv/index.php?&115
Note that while it is called "state history archive" it has not only national level documents, but also many local ones. So, as per the same page, in 1922 the State History Archive is the one to receive back from the USSR many documents evacuated during WW1, such as many parish church birth and death records, regional court proceedings, Riga school archives, etc. In 1935 a law is passed that mandates LSHA to receive not only government, but also municipal and non governmental organizations' archive documents.
Regarding WW2, the page states that as soon as the Soviets came into Latvia, they promptly renamed the archive into Latvian SSR State Archive, and created secret sections within LSHA. A bit later it is included as a department int the Soviet State Archive. As the Soviets retreat they evacuate parts of archive and some employees.
In 1941 the archive is renamed again into State Archive -- apparently by Germans. It is now part of General directorate for Education and Culture, department of Scientific institutions and archives.
In 1944 the LSHA is under department of Scientific institutions, art and culture. In the same year, as the Soviet forces near Riga, the more valuable parts of archive are evacuated, first to Ēdole castle in Latvia, then in autumn - both from Ēdole castle and Riga - to Czechoslovakia.
All of the above leads me to assume that:
archives are considered important enough to be evacuated rather than destroyed, upon leaving;
the archive's value includes specialists who know its contents. I am quite prepared to suggest that the very same people who worked in LHSA during independent Latvia, probably for most part remained as employees during the first Soviet occupation, German occupation, and the second Soviet occupation.
I guess also that while the high command might be very interested in all archives, the local army on ground were much more interested in things more essential for immediate survival.
That would mean that even if there was command to destroy the unevacuated parts of archive, there was less interest in following that order during the retreat of the army, and quite probably some kind of sabotage of such command by the employees of the archive.
Consider also the many changes of management of the archive during war. It appears that while it was in some part important, it wasn't important enough not to toss it around.
And as a final thought, both sides managed to evacuate what they presumably thought was the most important parts. Perhaps they didn't consider the remaining part worth the effort.