This is hypothesized as to how they began, but back then they wouldn’t have used turf grass, the just cut down the trees and kept vegetation low. It was an entirely tactical use though. Then it’s believed that the concept at some point started morphing more into a sign of prestige and initially would have primarily consisted of low growing vegetation like thyme. Then of course eventually turf grass was introduced and the concept migrated around to various parts of the world. It was considered a sign of prestige since it was a lot of manual work and it generally meant you had to be able to afford a groundscrew to keep it consistently maintained. There was also the fact that you were showing people you didn’t need to use your own land for food production.
Then some time in the mid-1800s, rudimentary push mowers were invented and it began to become more accessible. By the mid-1900s almost every new American housing development had a lawn since the technology had become advanced and accessible enough for any middle or working class family to maintain a lawn on their own. This was also influenced by marketing and suburbanization.
So while it is believed the concept of a “lawn” started as a tactical defense mechanism, the modern concept is more closely and directly related to the rich/nobility using them as a status symbol. IMO they’re clearly still used as status symbols since it’s exceptionally common for people to judge others for how pristine their turf grass lawn is maintained. I’ve even recently had someone mention to me that they know how to tell who the trash is in the neighborhood based on their lawn. I know they’re also used for recreation, but that can even be considered as part of the status symbol aspect as a poor person might not have a lawn and would have to go to the park with the other lawnless riffraff for their recreation.
In my experience, with both coding and natural sciences, a slightly incorrect answer that you attempt to apply, realize is wrong in some way during initial testing/analysis, then you tweak until it’s correct, is very useful, especially compared to not receiving any answer or being ridiculed by internet randos.