What is the use of Brahmins in settlements?
According to this post on the Steam Community forums brahmin increase the productivity of the settlement.
The game doesn't tell you what purpose the brahmins serve when they initially start spawning in your settlements. However, once you randomly start running into the wastelanders on the road who want to sell you one, you can find out in their dialogue options. They state that having a brahmin will increase the productivity of the settlement it is located in.
As well, as stated in the game's help menu, increasing the happiness of a settlement results in an increase to its productivity, apart from preventing its revolt. So, my guess is that once you naturally increase a settlement's happiness to a certain level (I don't know the cut-off point), and therefore increase its productivity, a brahmin will spawn, as the concepts of "happiness," "productivity," and "brahmins" are interconnected.
I have only bought one brahmin so far, but I have six of them in my various settlements.
They can be used to carry caravans around and can be killed for their meat as said here. They can also be used to see dialogue actions and seemingly help boost productivity as well as said here:
"The game doesn't tell you what purpose the brahmins serve when they initially start spawning in your settlements. However, once you randomly start running into the wastelanders on the road who want to sell you one, you can find out in their dialogue options. They state that having a brahmin will increase the productivity of the settlement it is located in." (This quote plus the link comes from @SlashTag)
First of all I'm pretty sure Brahmin don't just spawn in your settlements, there is an NPC walking around selling Brahmin for 100 caps, and this person can usually be found anywhere between Sanctuary, Starlight Drive-in and Abernathy Farm.
I bought a brahmin off her and had to choose which settlement to send it to. I chose Starlight Drive-in and sure enough my Brahmin was there when I showed up so I built it a feeding tub.
I don't believe it's wise to buy brahmin for slaughtering purposes, I know they provide meat and leather but it isn't worth 100 caps a head. I do believe that brahmins produce fertilizer (shows up in 'junk' in your workbench).
Also, contrary to what many believe, you do not need brahmin to establish supply lines, I think you only need Local Leader perk (level 1) to do that, and supply line brahmin spawn automatically.