I find the inverse of that question to be equally fascinating - how *little* we actually know about many of these battles. For example, Pickett's Charge, on the third day of the battle of Gettysburg, is perhaps the most studied single event in American military history, but its truly surprising the amount of gaps in the narrative. We don't know what time the battle began, we don't know what time it ended, we don't know how many soldiers fought on either side, and the casualty estimates vary considerably. The reason for that is the answer to your question! Because of the sources.
A rule of thumb I learned in graduate school was that sources are less reliable the further removed from the event they are describing. Of course this is not always true, but it is helpful to keep in mind when answering your question and thinking about what we "know" about events like this.
Fortunately for historians, armies - like any large bureaucracy - maintain lots of records. At Gettysburg, you will find muster rolls and reports at the company, regimental, divisional, corps, and Army level. On both sides, and in English to boot! In addition, official records would also include written orders and communications between commanders and their subordinates, and commander's post-action official reports. These official records are very utilitarian, but can provide a basic background. And, as they are written in the moment by relevant historical actors, they tend to be an accurate account of what the person writing this record believed to be true at the time they wrote it.
Fortunately again for historians, beginning in the nineteenth century the spread of literacy in the Western world means that battles like Gettysburg were fought by literate armies. The soldiers in these armies, from the common private to General Meade and General Lee, wrote letters and kept diaries. Written at the time or in the immediate aftermath of the battle, these are also a useful tool to interpret the events of a major battle.
Finally, momentous battles like Waterloo or Gettysburg are often relitigated by the surviving participants for decades afterwards. Many of the surviving generals on both sides wrote memoirs of the war, justifying their decisions and placing blame. They also wrote letters to one another and to journalists, published articles, and gave speeches. These sources are useful, but must obviously be read as self-justifying accounts and treated with appropriate skepticism.
Through all of this, it is easy to conclude that the wealth of primary sources around large battles in the "modern" era make knowing all the facts easy. In fact, it is often the opposite. More often than not, these sources contradict each other greatly. Each participant in the battle brings a perspective narrowed by the fog of war, the intensity of combat, and the frailty of human memory. The only "bird's eye" view of the battle, from the commanding officers on either side, is also filtered by distance and the unreliability of the information coming to them, and of course their attempts to justify their decisions. Complicating all of this too is that each participant experienced the battle very differently, and while a general has a good overall sense of the battle from a distance, a private soldier in the front line of the charge of course experiences the battle far more viscerally and immediately, but generally lacks any context other than what is directly in front of them. .
To bring this all back to your question, historians of battles like Gettysburg must work to synthesize a huge number of contradictory sources in an attempt to create a narrative of an event. To do so, one needs to look at all of the sources in their entirety, and embrace the fact that at the end of the day some of the facts will never truly be known.
My favorite example of interpreting sources from large battles is Dwight Eisenhower's letter written in the event of the failure of the D-Day landings. (his edits included)
"Our landings in the Cherbourg-Havre area have failed to gain a satisfactory foothold and
the troops have been withdrawnI have withdrawn the troops.This particular decisionMy decision to attack at this time and place was based on the best information available. The troops, the air and the Navy did all that bravery and devotion to duty could do. If any blame or fault attaches to the attempt it is mine alone."-July 5
Reading this letter - with no other knowledge of the context - one would believe that the invasion had failed. Of course, we know that not to be the case, and can surmise that Eisenhower preemptively wrote this document in case of failure. Further context allows us to understand that this letter was intended to be a public and a political document. Eisenhower knew that the landing's failure would lead to his resignation or dismissal, and the promotion of a new allied commander. Eisenhower's edits, from a passive to an active voice, show he recognized that reality and placed the blame on himself and not the army that would eventually have to attempt a second invasion. Finally, we know that the battle of Normandy was fought on June 6, 1944, and that this letter was written the day before the landings. However the written date is July 5. As historians we have to ask, is all of our understanding of the month of the Battle of Normandy wrong, or was Eisenhower simply exhausted and made a mistake? Of course it is the latter, but that mistake - and this whole document - demonstrate the importance of close reading of historical sources.