The VRAM should only be written to if the background and sprites are turned off, during VBLANK, or in a few cases, HBLANK. Attempting to write to it outside of these times will cause erroneous results.
On NTSC NES systems, the screen is refreshed at 60hz, sixty times per second. The NES draws the screen from top to bottom, then has some time at the bottom where it is not drawing, and when the light beam moves back up to the top to draw the next scanline. During this time when it is not drawing, we have what is called VBLANK. This gives us a significant open window to write to the VRAM, updating the screen. HBLANK, of course, is the small amount to time when the light beam moves from the end of a scanline to the start of the next one (right back to left). To use this properly, an IRQ timer is generally needed, which will be discussed later.
If drawing a large amount to the screen, such as a large portion of the background (name table), or filling in a large amount of CHRRAM data, you must turn off drawing, disabling the background and sprites. The vblank only gives enough time to draw a couple columns of tiles. An attempt to do a large write to VRAM during vblank will overflow onto the non-vblank, in which the NES will be trying to draw the screen while you are writing to it. This will cause major problems.
When writing a small amount of data to VRAM, such as a column or two of name table data, and a few sprites, you can do this during vblank. This is generally where you will do all your drawing, as you could not turn off the screen each update for scrolling games and such.