There are are few ways this can be done.
One important example, is case of Phineas Cage who's accident lead to severe brain damage. This changed his behavior, which allowed scientist to connect physiology with behavior. Namely, left frontal lobe damage caused change in personality, without significant change in other important behaviors such as memory.
Same way we can look on naturally occurred brain damage via modern imaging techniques (X-ray, CT, MRI, fMRI) and connect those to behavioral abnormalities.
We can also learn about neural substrate of behavior by experimenting in the lab: by looking at effects of tissue damage. Basically, you ask "what happens if we damage this part of the brain". This way we can figure out parts of brain that regulate different parts of sleep by dissecting animal's brain stem in different regions.
Another option is to "look" at brain while it functions and detect important active regions. Here you can use any number of techniques: fMRI, EEG, direct electrode probing of brain regions, or in animals optical calcium imaging. Point is that in these experiments you ask (or make) your subjects to perform behavior X and see how and where that behavior activates neurons.