During compilation, external files are read in, such as
.aux files - auxiliary files - which contain for example information for cross-referencing
a .toc file for the table of contents, .lof and .lot files for list of figures and list of tables, respectively
possibly an .ind file which contains the processed index, a .bbl file containing bibliography commands and more.
If such an external file contains an error, it can go away by renaming the main document and recompiling. And it can come back afterwards.
For example, if a sectioning command or a caption command contains code with an error, after renaming it may happen that
on the next compiling run there's no error, the wrong code is just written into the external file (.toc etc.)
in the following run that file is read in and processed, so the error can occur again.
Check toc, lof and lot files for errors if it happens repeatedly. "Strange" errors can sometimes be resolved by removing the .aux files, as Caramdir said. Don't worry about removing such LaTeX-generated files: they will come back in the next run.
A good start for locating the error would be examining the content of the .log file.