All three parksCan you walk through a field of cows?Photo: Neil Theasby, CC BY-SA 2.0, Wikimedia Commons, cropped.
Yorkshire Dales
Because the land was divided up, the stone was already there and grazing animals needed keeping in. The long straight walls mostly date from Parliamentary enclosure, from the late 18th century into the 19th.

The Yorkshire Dales National Park estimates it has around 8,000 km of dry stone walls. They are not all the same age. The Park's farming fact sheet says small areas of land were enclosed by walls over the centuries, while the main enclosures came towards the end of the 18th century, when Enclosure Acts passed by Parliament led to the sub-division of meadow, pasture and much of the rough common grazing. The Dry Stone Walling Association takes a wider view of Britain and says many walls were built during agricultural enclosure between 1650 and 1850.
The stone itself was never in short supply. Walls were built from what could be cleared off the land, and the Association lists the same reasons you might guess: easier cultivation, safer animals and shelter from wind and rain for stock and crops. Clearing a field and fencing it turned out to be one job.
Once you know the history you can often make a reasonable guess at a wall's age. The Park's landscape character assessment describes small, often irregular fields around settlements as older, some going back to the 17th century, and long, straight walls striding across the hilltops as later still, from the Parliamentary enclosure period and on into the 19th century. This was not a neutral change. The Park notes that many small farmers and cottagers lost their common grazing rights because they could not meet the conditions set by enclosure commissioners.
The walls also carry small details worth looking out for. A report for Defra on stone walls of historic and landscape importance lists several:

A field wall is two walls leaning on one another. Most stand a little over 1.3 metres high and consist of a pair of stone faces, known as the double, tapering in towards the top. The Defra report gives a common sequence, shown here as a section.
The lack of mortar is the point of the design. The Association says that walls are built without mortar or cement so that they can settle naturally and resist frost damage, and that they do not need a concrete foundation. A wall is meant to flex a little as the weather works on it, and the Association says the great majority in the British Isles have lasted hundreds of years built this way.

They answer a different question: where to store hay and keep cattle in winter without carting everything through the snow. The Park says most field barns were built in the 18th and 19th centuries. Its Fieldbarn Design Guide describes a tidy annual cycle, especially associated with Swaledale, that ran as follows.
That is why so many barns look alike: a hay mew at one end, a shippon or byre with stalls for cattle at the other, and a low mucking-out hole. There are around 4,500 of them in the National Park today, and the Park says the barn and wall pattern in Upper Swaledale is recognised as one of the most distinctive agricultural landscapes in Western Europe. Swaledale and Arkengarthdale also form the largest Conservation Area in England.
Both walls and barns are now largely redundant for their original jobs. Silage has replaced much of the hay, and modern cattle sheds have replaced the byres. The Park's management plan estimated that half of its traditional barns and walls were thought to be in poor or very bad condition, and accepted that without sufficient funding not everything can or will be conserved. It reports 225 barns restored, repaired or brought back into use over the lifetime of that 2019 to 2024 plan, which is good news but small against the total.
Walling is a living craft, with its own qualifications and training, and the Dry Stone Walling Association runs courses through a network of regional branches. If you own a wall that needs repair, the Association's site is the place to look for a registered contractor, along with general guidance on the funding schemes available to farms. Rates and grants change, so check the current position with them or on GOV.UK.
The Countryside Code asks you to use gates, stiles or gaps, because climbing over boundaries can cause damage and put stock at risk. Do not take stones or balance new ones on top. If you see a collapsed section with sheep escaping, tell the farmer if you can find them.
The best way to see all this is on foot in Swaledale. The Sunday bus from Ribblehead runs in summer, as covered in our car-free guide to the Dales. Our note on crossing fields with livestock will help on the way, and the Lake District's hefted sheep make an interesting contrast: same hill-farming problem, with far fewer walls on the high ground.
All three parksCan you walk through a field of cows?Photo: Neil Theasby, CC BY-SA 2.0, Wikimedia Commons, cropped.
Lake DistrictWhy fell sheep stay put with no fencesPhoto: Julian Herzog, CC BY 4.0, Wikimedia Commons, cropped.