Unlike other organs, such as the heart or intestines, it seems much harder to discern what the brain is doing in the human body. How did scientists figure out the brain was responsible for information processing, thought, and control of the rest of the body?
Some functions of the brain are actually easier to discover than functions of the heart or kidneys or liver, for example.
To do this you hit a human at the head with a mallet (wooden hammer) and see what happens. When s/he recovers her or his consciousness, ask him or her to describe his/her experience. (Disclaimer: I do NOT recommend to anyone to perform a real experiment, one needs a lot of knowledge and experience to calculate the appropriate force of the hit, if one does not want to make a permanent damage. Consider this as a thought experiment).
This procedure was used for millenia in cases when we use modern anaesthesia at the time of surgery. It was still in use in the middle 19 century.
Therefore I suppose that at least some functions of the brain were well-known well before the beginning of history. One cannot tell exactly when this method was discovered, but we know that surgery was performed very long before the beginning of writing, and certainly many people had similar experience without any surgery.