I was reading a timeline of the Norman Conquest and I noticed that William built a lot of castles during his reign. Why did he do that?
The short answer is that William the Conqueror used castles to consolidate his authority over England, and castles were considered the best and most effective way to do this.
When William invaded England in 1066, England's fortifications had not developed along the same course as Norman and Frankish fortifications. English 'burhs' were a collection of buildings surrounded by a wall of either stone or wood (or some combination), and sometimes with either a ditch or an elevated earthwork. This would depend on the needs of the local lord, and their ability to finance and source a building project.
However, fortifications in Normandy developed much quicker because of the decentralized political structure of France, relative to England. While England was not always completely at peace with itself, the English Aristocracy did not experience nearly the same level of in-fighting as the Norman nobility did. In Normandy, you would have infighting among all classes of aristocrats seeking to expand their prestige, territory, and wealth by any means necessary. Some of this infighting was caused by William the Conqueror (then known as William the Bastard) coming to the Ducal throne of Normandy as a minor, and an illegitimate one at that. This left no strong, unifying force governing Normandy that could enforce a more stable political climate.
This situation of continuous expansionist ambitions through violence created a sort of 'arms race' among the Norman nobility and their neighbors. From this climate came advances in castle-building and mounted combat. These advances were not necessary on the other side of the channel. England had not suffered any major revolt or invasion since 1016, with primary military action focusing on Wales.
On arrival in Pevensey in September 1066, William almost immediately constructed a motte-and-bailey castle there, and another at Hastings, to serve as bases of operations as he harassed the countryside south of London in order to draw Harold Godwinson out. These castles were raised in a matter of weeks, as the Battle of Hastings was fought on 14 October. They were little more than wooden structures atop an earthwork, which would have been constructed effectively from forced labor from the local populace. In fact, many subsequent castle mounds would be constructed effectively from forced labor. The construction of the castle at Hastings is actually depicted in the Bayeux Tapestry (tituli 45).
The Norman Conquest of England is often displayed as an overnight success, won in a single day. However, William did encounter several periods of resistance to his rule, necessitating an effective purge of the English aristocracy, which William replaced with his own Norman vassals. William and his vassals were largely more invested in their ancestral lands in Normandy, and a major reason for the Norman Conquest was to fund military activity in Normandy using England's superior system of taxation. However, if most of their time was going to be spent in Normandy, where land was considered far more prestigious and valuable, their interests in England would have to be protected in their absence. According to Philippe Contamine:
In order to hold the country, William and his barons resorted to the construction of motte and bailey castles for which all that was needed was a group of [laborers] and a few specialist carpenters. These castles were established following an overall strategic plan, which entailed protection of Channel ports, crossing-points of rivers, and a remarkable concentration around London an Coventry, that is around the two great nodal centres of communications in medieval England.
This allowed the Norman aristocracy to maintain control of the country in absentia so they could focus on their pressing needs in France to either expand or defend their territory.
Castles formed a military base, a symbol of power and dominance, and enabled the aristocracy to establish control over strategically important locales. John France actually makes the point that not all castles are built in a location that seems immediately obvious because they are not always for a specifically militaristic purpose, but can be just to demonstrate the power of a local magnate. The primary sources take it for granted that this is normal behaviour for William
So, to summarize: William built so many castles because he was creating a system by which he, an invader, could control a country that had not previously needed this infrastructure. He did this so that he and the Norman lords who replaced the Anglo-Saxon aristocracy could effectively enforce their economic and political dominance.
Sources
David Bates, William the Conqueror - Definitive Biography of William I
David Carpenter, The Struggle for Mastery: Britain 1066-1284
John France, Western Warfare in the Age of the Crusades 1000-1300
Philippe Contamine, War in the Middle Ages
Matthew Strickland, War and Chivalry: The Conduct and Perception of War in England and Normandy, 1066-1217
R. Allen Brown, Allen Brown's English Castles - This one is a little bit dated, but has particularly good diagrams and analyses of individual castles. Be wary of Brown's use of feudalism to define social structure.