Is it okay to clear a Skyrim dungeon before it is needed for a questline?
Solution 1:
No, it appears to have no effect in most places. While there is no official documentation about the prevalence of these bugs, Skyrim is known to have several imperfections which have not been accommodated for in quality assurance and testing.
In other words, use caution.
More specifically, all clearing a dungeon does is raise the respawn time for that dungeon from 10 to 30 days. After the respawn time, people and plants, etc. will return, but not special items. There are certain dungeons which do have an impact on plot, though; most notably are the dungeons which typically contain Hrolfdir's Shield. If you clear those, you are stuck in the questline, and need to use the console to get around it.
Most of the time, things will just come back. But, some of the time, if a dungeon is particularly significant or impactful, something might break. Bear this in mind, and crawl wisely! Some dungeons will have a general impact on the game. The best advice I have is to not think about spoiling dungeons, and just enjoy the game.
In your specific case case: I have reason to believe that the units in Valtheim will be back in 30 game days, and you will then be able to complete the quest.
Source 1, Source 2. See: Radiant storytelling.