The battles known together as the Seven Days Battles were part of General McClellan's Peninsula Campaign. In late June of 1862, McClellan was moving his army closer to Richmond in an attempt to capture the Confederate capital.
That previous March, McClellan had landed his army on the Virginia Peninsula. As he moved inland over the next couple of months, Union forces encountered fierce resistance from the Confederate forces. However, by the end of May, the Union army had reached the outskirts of Richmond. A number of inconclusive battles were fought, but neither side seemed able to repel the other.
After Confederate General Johnston was wounded and replaced by General Lee, the Confederate forces began taking a more aggressive approach, despite being significantly outnumbered. Lee knew that his forces would not likely survive a prolonged siege. He felt that taking offensive action against the Union forces might serve to repel them and spoil their plans to take Richmond. In late June, Lee and his generals formulated a plan to strike at the Union army and divide its forces through a series of coordinated assaults. At the same time, McClellan, having received intelligence that Lee was planning an attack, planned his own offensive. As the two sides went on their own offensives starting on June 25th, a series of battles unfolded in the vicinity of Richmond that have since become known collectively as the Seven Days Battles.